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

8612def _and_then(t1, t2, ctx=None):
8613 t1 = _to_tactic(t1, ctx)
8614 t2 = _to_tactic(t2, ctx)
8615 if z3_debug():
8616 _z3_assert(t1.ctx == t2.ctx, "Context mismatch")
8617 return Tactic(Z3_tactic_and_then(t1.ctx.ref(), t1.tactic, t2.tactic), t1.ctx)
8618
8619
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 4776 of file z3py.py.

4776def _array_select(ar, arg):
4777 if isinstance(arg, tuple):
4778 args = [ar.sort().domain_n(i).cast(arg[i]) for i in range(len(arg))]
4779 _args, sz = _to_ast_array(args)
4780 return _to_expr_ref(Z3_mk_select_n(ar.ctx_ref(), ar.as_ast(), sz, _args), ar.ctx)
4781 arg = ar.sort().domain().cast(arg)
4782 return _to_expr_ref(Z3_mk_select(ar.ctx_ref(), ar.as_ast(), arg.as_ast()), ar.ctx)
4783
4784
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 525 of file z3py.py.

525def _ast_kind(ctx : Context, a : Any) -> int:
526 if is_ast(a):
527 a = a.as_ast()
528 return Z3_get_ast_kind(ctx.ref(), a)
529
530
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 4337 of file z3py.py.

4337def _check_bv_args(a, b):
4338 if z3_debug():
4339 _z3_assert(is_bv(a) or is_bv(b), "First or second argument must be a Z3 bit-vector expression")
4340
4341

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

10724def _check_fp_args(a, b):
10725 if z3_debug():
10726 _z3_assert(is_fp(a) or is_fp(b), "First or second argument must be a Z3 floating-point expression")
10727
10728

◆ _check_same_sort()

_check_same_sort (   a,
  b,
  ctx = None 
)
protected

Definition at line 1292 of file z3py.py.

1292def _check_same_sort(a, b, ctx=None):
1293 if not isinstance(a, ExprRef):
1294 return False
1295 if not isinstance(b, ExprRef):
1296 return False
1297 if ctx is None:
1298 ctx = a.ctx
1299
1300 a_sort = Z3_get_sort(ctx.ctx, a.ast)
1301 b_sort = Z3_get_sort(ctx.ctx, b.ast)
1302 return Z3_is_eq_sort(ctx.ctx, a_sort, b_sort)
1303
1304
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 11167 of file z3py.py.

11167def _coerce_char(ch, ctx=None):
11168 if isinstance(ch, str):
11169 ctx = _get_ctx(ctx)
11170 ch = CharVal(ch, ctx)
11171 if not is_expr(ch):
11172 raise Z3Exception("Character expression expected")
11173 return ch
11174

◆ _coerce_expr_list()

_coerce_expr_list (   alist,
  ctx = None 
)
protected

Definition at line 1336 of file z3py.py.

1336def _coerce_expr_list(alist, ctx=None):
1337 has_expr = False
1338 for a in alist:
1339 if is_expr(a):
1340 has_expr = True
1341 break
1342 if not has_expr:
1343 alist = [_py2expr(a, ctx) for a in alist]
1344 s = _reduce(_coerce_expr_merge, alist, None)
1345 return [s.cast(a) for a in alist]
1346
1347

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

◆ _coerce_expr_merge()

_coerce_expr_merge (   s,
  a 
)
protected

Definition at line 1274 of file z3py.py.

1274def _coerce_expr_merge(s, a):
1275 if is_expr(a):
1276 s1 = a.sort()
1277 if s is None:
1278 return s1
1279 if s1.eq(s):
1280 return s
1281 elif s.subsort(s1):
1282 return s1
1283 elif s1.subsort(s):
1284 return s
1285 else:
1286 if z3_debug():
1287 _z3_assert(s1.ctx == s.ctx, "context mismatch")
1288 _z3_assert(False, "sort mismatch")
1289 else:
1290 return s
1291

Referenced by _coerce_exprs().

◆ _coerce_exprs()

_coerce_exprs (   a,
  b,
  ctx = None 
)
protected

Definition at line 1305 of file z3py.py.

1305def _coerce_exprs(a, b, ctx=None):
1306 if not is_expr(a) and not is_expr(b):
1307 a = _py2expr(a, ctx)
1308 b = _py2expr(b, ctx)
1309 if isinstance(a, str) and isinstance(b, SeqRef):
1310 a = StringVal(a, b.ctx)
1311 if isinstance(b, str) and isinstance(a, SeqRef):
1312 b = StringVal(b, a.ctx)
1313 if isinstance(a, float) and isinstance(b, ArithRef):
1314 a = RealVal(a, b.ctx)
1315 if isinstance(b, float) and isinstance(a, ArithRef):
1316 b = RealVal(b, a.ctx)
1317
1318 if _check_same_sort(a, b, ctx):
1319 return (a, b)
1320
1321 s = None
1322 s = _coerce_expr_merge(s, a)
1323 s = _coerce_expr_merge(s, b)
1324 a = s.cast(a)
1325 b = s.cast(b)
1326 return (a, b)
1327
1328

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

9673def _coerce_fp_expr_list(alist, ctx):
9674 first_fp_sort = None
9675 for a in alist:
9676 if is_fp(a):
9677 if first_fp_sort is None:
9678 first_fp_sort = a.sort()
9679 elif first_fp_sort == a.sort():
9680 pass # OK, same as before
9681 else:
9682 # we saw at least 2 different float sorts; something will
9683 # throw a sort mismatch later, for now assume None.
9684 first_fp_sort = None
9685 break
9686
9687 r = []
9688 for i in range(len(alist)):
9689 a = alist[i]
9690 is_repr = isinstance(a, str) and a.contains("2**(") and a.endswith(")")
9691 if is_repr or _is_int(a) or isinstance(a, (float, bool)):
9692 r.append(FPVal(a, None, first_fp_sort, ctx))
9693 else:
9694 r.append(a)
9695 return _coerce_expr_list(r, ctx)
9696
9697
9698# FP Sorts
9699

◆ _coerce_seq()

_coerce_seq (   s,
  ctx = None 
)
protected

Definition at line 11217 of file z3py.py.

11217def _coerce_seq(s, ctx=None):
11218 if isinstance(s, str):
11219 ctx = _get_ctx(ctx)
11220 s = StringVal(s, ctx)
11221 if not is_expr(s):
11222 raise Z3Exception("Non-expression passed as a sequence")
11223 if not is_seq(s):
11224 raise Z3Exception("Non-sequence passed as a sequence")
11225 return s
11226
11227

Referenced by Concat().

◆ _ctx_from_ast_arg_list()

_ctx_from_ast_arg_list (   args,
  default_ctx = None 
)
protected

Definition at line 531 of file z3py.py.

531def _ctx_from_ast_arg_list(args, default_ctx=None):
532 ctx = None
533 for a in args:
534 if is_ast(a) or is_probe(a):
535 if ctx is None:
536 ctx = a.ctx
537 else:
538 if z3_debug():
539 _z3_assert(ctx == a.ctx, "Context mismatch")
540 if ctx is None:
541 ctx = default_ctx
542 return ctx
543
544

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

545def _ctx_from_ast_args(*args):
546 return _ctx_from_ast_arg_list(args)
547
548

◆ _dflt_fps()

_dflt_fps (   ctx = None)
protected

Definition at line 9669 of file z3py.py.

9669def _dflt_fps(ctx=None):
9670 return get_default_fp_sort(ctx)
9671
9672

◆ _dflt_rm()

_dflt_rm (   ctx = None)
protected

Definition at line 9665 of file z3py.py.

9665def _dflt_rm(ctx=None):
9666 return get_default_rounding_mode(ctx)
9667
9668

◆ _dict2darray()

_dict2darray (   decls,
  ctx 
)
protected

Definition at line 9538 of file z3py.py.

9538def _dict2darray(decls, ctx):
9539 sz = len(decls)
9540 _names = (Symbol * sz)()
9541 _decls = (FuncDecl * sz)()
9542 i = 0
9543 for k in decls:
9544 v = decls[k]
9545 if z3_debug():
9546 _z3_assert(isinstance(k, str), "String expected")
9547 _z3_assert(is_func_decl(v) or is_const(v), "Z3 declaration or constant expected")
9548 _names[i] = to_symbol(k, ctx)
9549 if is_const(v):
9550 _decls[i] = v.decl().ast
9551 else:
9552 _decls[i] = v.ast
9553 i = i + 1
9554 return sz, _names, _decls
9555

◆ _dict2sarray()

_dict2sarray (   sorts,
  ctx 
)
protected

Definition at line 9522 of file z3py.py.

9522def _dict2sarray(sorts, ctx):
9523 sz = len(sorts)
9524 _names = (Symbol * sz)()
9525 _sorts = (Sort * sz)()
9526 i = 0
9527 for k in sorts:
9528 v = sorts[k]
9529 if z3_debug():
9530 _z3_assert(isinstance(k, str), "String expected")
9531 _z3_assert(is_sort(v), "Z3 sort expected")
9532 _names[i] = to_symbol(k, ctx)
9533 _sorts[i] = v.ast
9534 i = i + 1
9535 return sz, _names, _sorts
9536
9537

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

290def _get_ctx(ctx) -> Context:
291 if ctx is None:
292 return main_ctx()
293 else:
294 return ctx
295
296

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

11228def _get_ctx2(a, b, ctx=None):
11229 if is_expr(a):
11230 return a.ctx
11231 if is_expr(b):
11232 return b.ctx
11233 if ctx is None:
11234 ctx = main_ctx()
11235 return ctx
11236
11237

◆ _global_on_model()

_global_on_model (   ctx)
protected

Definition at line 8116 of file z3py.py.

8116def _global_on_model(ctx):
8117 (fn, mdl) = _on_models[ctx]
8118 fn(mdl)
8119
8120

◆ _has_probe()

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

Definition at line 1977 of file z3py.py.

1977def _has_probe(args):
1978 """Return `True` if one of the elements of the given collection is a Z3 probe."""
1979 for arg in args:
1980 if is_probe(arg):
1981 return True
1982 return False
1983
1984

Referenced by And(), and Or().

◆ _is_algebraic()

_is_algebraic (   ctx,
  a 
)
protected

Definition at line 2874 of file z3py.py.

2874def _is_algebraic(ctx, a):
2875 return Z3_is_algebraic_number(ctx.ref(), a)
2876
2877
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 2870 of file z3py.py.

2870def _is_numeral(ctx, a):
2871 return Z3_is_numeral_ast(ctx.ref(), a)
2872
2873
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 1534 of file z3py.py.

1534def _mk_bin(f, a, b):
1535 args = (Ast * 2)()
1536 if z3_debug():
1537 _z3_assert(a.ctx == b.ctx, "Context mismatch")
1538 args[0] = a.as_ast()
1539 args[1] = b.as_ast()
1540 return f(a.ctx.ref(), 2, args)
1541
1542

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

10512def _mk_fp_bin(f, rm, a, b, ctx):
10513 ctx = _get_ctx(ctx)
10514 [a, b] = _coerce_fp_expr_list([a, b], ctx)
10515 if z3_debug():
10516 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
10517 _z3_assert(is_fp(a) or is_fp(b), "Second or third argument must be a Z3 floating-point expression")
10518 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast()), ctx)
10519
10520

◆ _mk_fp_bin_norm()

_mk_fp_bin_norm (   f,
  a,
  b,
  ctx 
)
protected

Definition at line 10521 of file z3py.py.

10521def _mk_fp_bin_norm(f, a, b, ctx):
10522 ctx = _get_ctx(ctx)
10523 [a, b] = _coerce_fp_expr_list([a, b], ctx)
10524 if z3_debug():
10525 _z3_assert(is_fp(a) or is_fp(b), "First or second argument must be a Z3 floating-point expression")
10526 return FPRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
10527
10528

◆ _mk_fp_bin_pred()

_mk_fp_bin_pred (   f,
  a,
  b,
  ctx 
)
protected

Definition at line 10529 of file z3py.py.

10529def _mk_fp_bin_pred(f, a, b, ctx):
10530 ctx = _get_ctx(ctx)
10531 [a, b] = _coerce_fp_expr_list([a, b], ctx)
10532 if z3_debug():
10533 _z3_assert(is_fp(a) or is_fp(b), "First or second argument must be a Z3 floating-point expression")
10534 return BoolRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
10535
10536

◆ _mk_fp_tern()

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

Definition at line 10537 of file z3py.py.

10537def _mk_fp_tern(f, rm, a, b, c, ctx):
10538 ctx = _get_ctx(ctx)
10539 [a, b, c] = _coerce_fp_expr_list([a, b, c], ctx)
10540 if z3_debug():
10541 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
10542 _z3_assert(is_fp(a) or is_fp(b) or is_fp(
10543 c), "Second, third or fourth argument must be a Z3 floating-point expression")
10544 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
10545
10546

◆ _mk_fp_unary()

_mk_fp_unary (   f,
  rm,
  a,
  ctx 
)
protected

Definition at line 10495 of file z3py.py.

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

◆ _mk_fp_unary_pred()

_mk_fp_unary_pred (   f,
  a,
  ctx 
)
protected

Definition at line 10504 of file z3py.py.

10504def _mk_fp_unary_pred(f, a, ctx):
10505 ctx = _get_ctx(ctx)
10506 [a] = _coerce_fp_expr_list([a], ctx)
10507 if z3_debug():
10508 _z3_assert(is_fp(a), "First argument must be a Z3 floating-point expression")
10509 return BoolRef(f(ctx.ref(), a.as_ast()), ctx)
10510
10511

◆ _mk_quantifier()

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

Definition at line 2333 of file z3py.py.

2333def _mk_quantifier(is_forall, vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2334 if z3_debug():
2335 _z3_assert(is_bool(body) or is_app(vs) or (len(vs) > 0 and is_app(vs[0])), "Z3 expression expected")
2336 _z3_assert(is_const(vs) or (len(vs) > 0 and all([is_const(v) for v in vs])), "Invalid bounded variable(s)")
2337 _z3_assert(all([is_pattern(a) or is_expr(a) for a in patterns]), "Z3 patterns expected")
2338 _z3_assert(all([is_expr(p) for p in no_patterns]), "no patterns are Z3 expressions")
2339 if is_app(vs):
2340 ctx = vs.ctx
2341 vs = [vs]
2342 else:
2343 ctx = vs[0].ctx
2344 if not is_expr(body):
2345 body = BoolVal(body, ctx)
2346 num_vars = len(vs)
2347 if num_vars == 0:
2348 return body
2349 _vs = (Ast * num_vars)()
2350 for i in range(num_vars):
2351 # TODO: Check if is constant
2352 _vs[i] = vs[i].as_ast()
2353 patterns = [_to_pattern(p) for p in patterns]
2354 num_pats = len(patterns)
2355 _pats = (Pattern * num_pats)()
2356 for i in range(num_pats):
2357 _pats[i] = patterns[i].ast
2358 _no_pats, num_no_pats = _to_ast_array(no_patterns)
2359 qid = to_symbol(qid, ctx)
2360 skid = to_symbol(skid, ctx)
2361 return QuantifierRef(Z3_mk_quantifier_const_ex(ctx.ref(), is_forall, weight, qid, skid,
2362 num_vars, _vs,
2363 num_pats, _pats,
2364 num_no_pats, _no_pats,
2365 body.as_ast()), ctx)
2366
2367
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 8620 of file z3py.py.

8620def _or_else(t1, t2, ctx=None):
8621 t1 = _to_tactic(t1, ctx)
8622 t2 = _to_tactic(t2, ctx)
8623 if z3_debug():
8624 _z3_assert(t1.ctx == t2.ctx, "Context mismatch")
8625 return Tactic(Z3_tactic_or_else(t1.ctx.ref(), t1.tactic, t2.tactic), t1.ctx)
8626
8627
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 9311 of file z3py.py.

9311def _pb_args_coeffs(args, default_ctx=None):
9312 args = _get_args_ast_list(args)
9313 if len(args) == 0:
9314 return _get_ctx(default_ctx), 0, (Ast * 0)(), (ctypes.c_int * 0)()
9315 args = [_reorder_pb_arg(arg) for arg in args]
9316 args, coeffs = zip(*args)
9317 if z3_debug():
9318 _z3_assert(len(args) > 0, "Non empty list of arguments expected")
9319 ctx = _ctx_from_ast_arg_list(args)
9320 if z3_debug():
9321 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
9322 args = _coerce_expr_list(args, ctx)
9323 _args, sz = _to_ast_array(args)
9324 _coeffs = (ctypes.c_int * len(coeffs))()
9325 for i in range(len(coeffs)):
9326 _z3_check_cint_overflow(coeffs[i], "coefficient")
9327 _coeffs[i] = coeffs[i]
9328 return ctx, sz, _args, _coeffs, args
9329
9330

◆ _probe_and()

_probe_and (   args,
  ctx 
)
protected

Definition at line 9035 of file z3py.py.

9035def _probe_and(args, ctx):
9036 return _probe_nary(Z3_probe_and, args, ctx)
9037
9038

Referenced by And().

◆ _probe_nary()

_probe_nary (   f,
  args,
  ctx 
)
protected

Definition at line 9025 of file z3py.py.

9025def _probe_nary(f, args, ctx):
9026 if z3_debug():
9027 _z3_assert(len(args) > 0, "At least one argument expected")
9028 num = len(args)
9029 r = _to_probe(args[0], ctx)
9030 for i in range(num - 1):
9031 r = Probe(f(ctx.ref(), r.probe, _to_probe(args[i + 1], ctx).probe), ctx)
9032 return r
9033
9034

◆ _probe_or()

_probe_or (   args,
  ctx 
)
protected

Definition at line 9039 of file z3py.py.

9039def _probe_or(args, ctx):
9040 return _probe_nary(Z3_probe_or, args, ctx)
9041
9042

Referenced by Or().

◆ _prove_html()

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

Definition at line 9502 of file z3py.py.

9502def _prove_html(claim, show=False, **keywords):
9503 """Version of function `prove` that renders HTML."""
9504 if z3_debug():
9505 _z3_assert(is_bool(claim), "Z3 Boolean expression expected")
9506 s = Solver()
9507 s.set(**keywords)
9508 s.add(Not(claim))
9509 if show:
9510 print(s)
9511 r = s.check()
9512 if r == unsat:
9513 print("<b>proved</b>")
9514 elif r == unknown:
9515 print("<b>failed to prove</b>")
9516 print(s.model())
9517 else:
9518 print("<b>counterexample</b>")
9519 print(s.model())
9520
9521

◆ _py2expr()

_py2expr (   a,
  ctx = None 
)
protected

Definition at line 3275 of file z3py.py.

3275def _py2expr(a, ctx=None):
3276 if isinstance(a, bool):
3277 return BoolVal(a, ctx)
3278 if _is_int(a):
3279 return IntVal(a, ctx)
3280 if isinstance(a, float):
3281 return RealVal(a, ctx)
3282 if isinstance(a, str):
3283 return StringVal(a, ctx)
3284 if is_expr(a):
3285 return a
3286 if z3_debug():
3287 _z3_assert(False, "Python bool, int, long or float expected")
3288
3289

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

◆ _reduce()

_reduce (   func,
  sequence,
  initial 
)
protected

Definition at line 1329 of file z3py.py.

1329def _reduce(func, sequence, initial):
1330 result = initial
1331 for element in sequence:
1332 result = func(result, element)
1333 return result
1334
1335

Referenced by _coerce_expr_list().

◆ _reorder_pb_arg()

_reorder_pb_arg (   arg)
protected

Definition at line 9304 of file z3py.py.

9304def _reorder_pb_arg(arg):
9305 a, b = arg
9306 if not _is_int(b) and _is_int(a):
9307 return b, a
9308 return arg
9309
9310

◆ _solve_html()

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

Definition at line 9453 of file z3py.py.

9453def _solve_html(*args, **keywords):
9454 """Version of function `solve` that renders HTML output."""
9455 show = keywords.pop("show", False)
9456 s = Solver()
9457 s.set(**keywords)
9458 s.add(*args)
9459 if show:
9460 print("<b>Problem:</b>")
9461 print(s)
9462 r = s.check()
9463 if r == unsat:
9464 print("<b>no solution</b>")
9465 elif r == unknown:
9466 print("<b>failed to solve</b>")
9467 try:
9468 print(s.model())
9469 except Z3Exception:
9470 return
9471 else:
9472 if show:
9473 print("<b>Solution:</b>")
9474 print(s.model())
9475
9476

◆ _solve_using_html()

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

Definition at line 9477 of file z3py.py.

9477def _solve_using_html(s, *args, **keywords):
9478 """Version of function `solve_using` that renders HTML."""
9479 show = keywords.pop("show", False)
9480 if z3_debug():
9481 _z3_assert(isinstance(s, Solver), "Solver object expected")
9482 s.set(**keywords)
9483 s.add(*args)
9484 if show:
9485 print("<b>Problem:</b>")
9486 print(s)
9487 r = s.check()
9488 if r == unsat:
9489 print("<b>no solution</b>")
9490 elif r == unknown:
9491 print("<b>failed to solve</b>")
9492 try:
9493 print(s.model())
9494 except Z3Exception:
9495 return
9496 else:
9497 if show:
9498 print("<b>Solution:</b>")
9499 print(s.model())
9500
9501

◆ _sort()

SortRef _sort ( Context  ctx,
Any  a 
)
protected

Definition at line 729 of file z3py.py.

729def _sort(ctx : Context, a : Any) -> SortRef:
730 return _to_sort_ref(Z3_get_sort(ctx.ref(), a), ctx)
731
732

◆ _sort_kind()

_sort_kind (   ctx,
  s 
)
protected

Sorts.

Definition at line 589 of file z3py.py.

589def _sort_kind(ctx, s):
590 return Z3_get_sort_kind(ctx.ref(), s)
591
592
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 557 of file z3py.py.

557def _to_ast_array(args):
558 sz = len(args)
559 _args = (Ast * sz)()
560 for i in range(sz):
561 _args[i] = args[i].as_ast()
562 return _args, sz
563
564

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

573def _to_ast_ref(a, ctx):
574 k = _ast_kind(ctx, a)
575 if k == Z3_SORT_AST:
576 return _to_sort_ref(a, ctx)
577 elif k == Z3_FUNC_DECL_AST:
578 return _to_func_decl_ref(a, ctx)
579 else:
580 return _to_expr_ref(a, ctx)
581
582

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

◆ _to_expr_ref()

_to_expr_ref (   a,
  ctx 
)
protected

Definition at line 1224 of file z3py.py.

1224def _to_expr_ref(a, ctx):
1225 if isinstance(a, Pattern):
1226 return PatternRef(a, ctx)
1227 ctx_ref = ctx.ref()
1228 k = Z3_get_ast_kind(ctx_ref, a)
1229 if k == Z3_QUANTIFIER_AST:
1230 return QuantifierRef(a, ctx)
1231 sk = Z3_get_sort_kind(ctx_ref, Z3_get_sort(ctx_ref, a))
1232 if sk == Z3_BOOL_SORT:
1233 return BoolRef(a, ctx)
1234 if sk == Z3_INT_SORT:
1235 if k == Z3_NUMERAL_AST:
1236 return IntNumRef(a, ctx)
1237 return ArithRef(a, ctx)
1238 if sk == Z3_REAL_SORT:
1239 if k == Z3_NUMERAL_AST:
1240 return RatNumRef(a, ctx)
1241 if _is_algebraic(ctx, a):
1242 return AlgebraicNumRef(a, ctx)
1243 return ArithRef(a, ctx)
1244 if sk == Z3_BV_SORT:
1245 if k == Z3_NUMERAL_AST:
1246 return BitVecNumRef(a, ctx)
1247 else:
1248 return BitVecRef(a, ctx)
1249 if sk == Z3_ARRAY_SORT:
1250 return ArrayRef(a, ctx)
1251 if sk == Z3_DATATYPE_SORT:
1252 return DatatypeRef(a, ctx)
1253 if sk == Z3_FLOATING_POINT_SORT:
1254 if k == Z3_APP_AST and _is_numeral(ctx, a):
1255 return FPNumRef(a, ctx)
1256 else:
1257 return FPRef(a, ctx)
1258 if sk == Z3_FINITE_DOMAIN_SORT:
1259 if k == Z3_NUMERAL_AST:
1260 return FiniteDomainNumRef(a, ctx)
1261 else:
1262 return FiniteDomainRef(a, ctx)
1263 if sk == Z3_ROUNDING_MODE_SORT:
1264 return FPRMRef(a, ctx)
1265 if sk == Z3_SEQ_SORT:
1266 return SeqRef(a, ctx)
1267 if sk == Z3_CHAR_SORT:
1268 return CharRef(a, ctx)
1269 if sk == Z3_RE_SORT:
1270 return ReRef(a, ctx)
1271 return ExprRef(a, ctx)
1272
1273

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(), ExprRef.update(), FuncEntry.value(), and Var().

◆ _to_float_str()

_to_float_str (   val,
  exp = 0 
)
protected

Definition at line 10257 of file z3py.py.

10257def _to_float_str(val, exp=0):
10258 if isinstance(val, float):
10259 if math.isnan(val):
10260 res = "NaN"
10261 elif val == 0.0:
10262 sone = math.copysign(1.0, val)
10263 if sone < 0.0:
10264 return "-0.0"
10265 else:
10266 return "+0.0"
10267 elif val == float("+inf"):
10268 res = "+oo"
10269 elif val == float("-inf"):
10270 res = "-oo"
10271 else:
10272 v = val.as_integer_ratio()
10273 num = v[0]
10274 den = v[1]
10275 rvs = str(num) + "/" + str(den)
10276 res = rvs + "p" + _to_int_str(exp)
10277 elif isinstance(val, bool):
10278 if val:
10279 res = "1.0"
10280 else:
10281 res = "0.0"
10282 elif _is_int(val):
10283 res = str(val)
10284 elif isinstance(val, str):
10285 inx = val.find("*(2**")
10286 if inx == -1:
10287 res = val
10288 elif val[-1] == ")":
10289 res = val[0:inx]
10290 exp = str(int(val[inx + 5:-1]) + int(exp))
10291 else:
10292 _z3_assert(False, "String does not have floating-point numeral form.")
10293 elif z3_debug():
10294 _z3_assert(False, "Python value cannot be used to create floating-point numerals.")
10295 if exp == 0:
10296 return res
10297 else:
10298 return res + "p" + exp
10299
10300

◆ _to_func_decl_array()

_to_func_decl_array (   args)
protected

Definition at line 549 of file z3py.py.

549def _to_func_decl_array(args):
550 sz = len(args)
551 _args = (FuncDecl * sz)()
552 for i in range(sz):
553 _args[i] = args[i].as_func_decl()
554 return _args, sz
555
556

◆ _to_func_decl_ref()

_to_func_decl_ref (   a,
  ctx 
)
protected

Definition at line 965 of file z3py.py.

965def _to_func_decl_ref(a, ctx):
966 return FuncDeclRef(a, ctx)
967
968

Referenced by _to_ast_ref().

◆ _to_goal()

_to_goal (   a)
protected

Definition at line 8596 of file z3py.py.

8596def _to_goal(a):
8597 if isinstance(a, BoolRef):
8598 goal = Goal(ctx=a.ctx)
8599 goal.add(a)
8600 return goal
8601 else:
8602 return a
8603
8604

◆ _to_int_str()

_to_int_str (   val)
protected

Definition at line 3324 of file z3py.py.

3324def _to_int_str(val):
3325 if isinstance(val, float):
3326 return str(int(val))
3327 elif isinstance(val, bool):
3328 if val:
3329 return "1"
3330 else:
3331 return "0"
3332 else:
3333 return str(val)
3334
3335

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

2111def _to_pattern(arg):
2112 if is_pattern(arg):
2113 return arg
2114 else:
2115 return MultiPattern(arg)
2116

Referenced by _mk_quantifier().

◆ _to_probe()

_to_probe (   p,
  ctx = None 
)
protected

Definition at line 8979 of file z3py.py.

8979def _to_probe(p, ctx=None):
8980 if is_probe(p):
8981 return p
8982 else:
8983 return Probe(p, ctx)
8984
8985

◆ _to_ref_array()

_to_ref_array (   ref,
  args 
)
protected

Definition at line 565 of file z3py.py.

565def _to_ref_array(ref, args):
566 sz = len(args)
567 _args = (ref * sz)()
568 for i in range(sz):
569 _args[i] = args[i].as_ast()
570 return _args, sz
571
572

◆ _to_sort_ref()

_to_sort_ref (   s,
  ctx 
)
protected

Definition at line 698 of file z3py.py.

698def _to_sort_ref(s, ctx):
699 if z3_debug():
700 _z3_assert(isinstance(s, Sort), "Z3 Sort expected")
701 k = _sort_kind(ctx, s)
702 if k == Z3_BOOL_SORT:
703 return BoolSortRef(s, ctx)
704 elif k == Z3_INT_SORT or k == Z3_REAL_SORT:
705 return ArithSortRef(s, ctx)
706 elif k == Z3_BV_SORT:
707 return BitVecSortRef(s, ctx)
708 elif k == Z3_ARRAY_SORT:
709 return ArraySortRef(s, ctx)
710 elif k == Z3_DATATYPE_SORT:
711 return DatatypeSortRef(s, ctx)
712 elif k == Z3_FINITE_DOMAIN_SORT:
713 return FiniteDomainSortRef(s, ctx)
714 elif k == Z3_FLOATING_POINT_SORT:
715 return FPSortRef(s, ctx)
716 elif k == Z3_ROUNDING_MODE_SORT:
717 return FPRMSortRef(s, ctx)
718 elif k == Z3_RE_SORT:
719 return ReSortRef(s, ctx)
720 elif k == Z3_SEQ_SORT:
721 return SeqSortRef(s, ctx)
722 elif k == Z3_CHAR_SORT:
723 return CharSortRef(s, ctx)
724 elif k == Z3_TYPE_VAR:
725 return TypeVarRef(s, ctx)
726 return SortRef(s, ctx)
727
728

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

8605def _to_tactic(t, ctx=None):
8606 if isinstance(t, Tactic):
8607 return t
8608 else:
8609 return Tactic(t, ctx)
8610
8611

◆ _valid_accessor()

_valid_accessor (   acc)
protected

Datatypes.

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

Definition at line 5208 of file z3py.py.

5208def _valid_accessor(acc):
5209 """Return `True` if acc is pair of the form (String, Datatype or Sort). """
5210 if not isinstance(acc, tuple):
5211 return False
5212 if len(acc) != 2:
5213 return False
5214 return isinstance(acc[0], str) and (isinstance(acc[1], Datatype) or is_sort(acc[1]))
5215
5216

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

9263def Abs(arg):
9264 """Create the absolute value of an arithmetic expression"""
9265 return If(arg > 0, arg, -arg)
9266
9267

◆ AllChar()

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

Definition at line 11700 of file z3py.py.

11700def AllChar(regex_sort, ctx=None):
11701 """Create a regular expression that accepts all single character strings
11702 """
11703 return ReRef(Z3_mk_re_allchar(regex_sort.ctx_ref(), regex_sort.ast), regex_sort.ctx)
11704
11705# Special Relations
11706
11707
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 1985 of file z3py.py.

1985def And(*args):
1986 """Create a Z3 and-expression or and-probe.
1987
1988 >>> p, q, r = Bools('p q r')
1989 >>> And(p, q, r)
1990 And(p, q, r)
1991 >>> P = BoolVector('p', 5)
1992 >>> And(P)
1993 And(p__0, p__1, p__2, p__3, p__4)
1994 """
1995 last_arg = None
1996 if len(args) > 0:
1997 last_arg = args[len(args) - 1]
1998 if isinstance(last_arg, Context):
1999 ctx = args[len(args) - 1]
2000 args = args[:len(args) - 1]
2001 elif len(args) == 1 and isinstance(args[0], AstVector):
2002 ctx = args[0].ctx
2003 args = [a for a in args[0]]
2004 else:
2005 ctx = None
2006 args = _get_args(args)
2007 ctx = _get_ctx(_ctx_from_ast_arg_list(args, ctx))
2008 if z3_debug():
2009 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression or probe")
2010 if _has_probe(args):
2011 return _probe_and(args, ctx)
2012 else:
2013 args = _coerce_expr_list(args, ctx)
2014 _args, sz = _to_ast_array(args)
2015 return BoolRef(Z3_mk_and(ctx.ref(), sz, _args), ctx)
2016
2017
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 8628 of file z3py.py.

8628def AndThen(*ts, **ks):
8629 """Return a tactic that applies the tactics in `*ts` in sequence.
8630
8631 >>> x, y = Ints('x y')
8632 >>> t = AndThen(Tactic('simplify'), Tactic('solve-eqs'))
8633 >>> t(And(x == 0, y > x + 1))
8634 [[Not(y <= 1)]]
8635 >>> t(And(x == 0, y > x + 1)).as_expr()
8636 Not(y <= 1)
8637 """
8638 if z3_debug():
8639 _z3_assert(len(ts) >= 2, "At least two arguments expected")
8640 ctx = ks.get("ctx", None)
8641 num = len(ts)
8642 r = ts[0]
8643 for i in range(num - 1):
8644 r = _and_then(r, ts[i + 1], ctx)
8645 return r
8646
8647

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

5657def args2params(arguments, keywords, ctx=None):
5658 """Convert python arguments into a Z3_params object.
5659 A ':' is added to the keywords, and '_' is replaced with '-'
5660
5661 >>> args2params(['model', True, 'relevancy', 2], {'elim_and' : True})
5662 (params model true relevancy 2 elim_and true)
5663 """
5664 if z3_debug():
5665 _z3_assert(len(arguments) % 2 == 0, "Argument list must have an even number of elements.")
5666 prev = None
5667 r = ParamsRef(ctx)
5668 for a in arguments:
5669 if prev is None:
5670 prev = a
5671 else:
5672 r.set(prev, a)
5673 prev = None
5674 for k in keywords:
5675 v = keywords[k]
5676 r.set(k, v)
5677 return r
5678
5679

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

4911def Array(name, *sorts):
4912 """Return an array constant named `name` with the given domain and range sorts.
4913
4914 >>> a = Array('a', IntSort(), IntSort())
4915 >>> a.sort()
4916 Array(Int, Int)
4917 >>> a[0]
4918 a[0]
4919 """
4920 s = ArraySort(sorts)
4921 ctx = s.ctx
4922 return ArrayRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), s.ast), ctx)
4923
4924
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 4878 of file z3py.py.

4878def ArraySort(*sig):
4879 """Return the Z3 array sort with the given domain and range sorts.
4880
4881 >>> A = ArraySort(IntSort(), BoolSort())
4882 >>> A
4883 Array(Int, Bool)
4884 >>> A.domain()
4885 Int
4886 >>> A.range()
4887 Bool
4888 >>> AA = ArraySort(IntSort(), A)
4889 >>> AA
4890 Array(Int, Array(Int, Bool))
4891 """
4892 sig = _get_args(sig)
4893 if z3_debug():
4894 _z3_assert(len(sig) > 1, "At least two arguments expected")
4895 arity = len(sig) - 1
4896 r = sig[arity]
4897 d = sig[0]
4898 if z3_debug():
4899 for s in sig:
4900 _z3_assert(is_sort(s), "Z3 sort expected")
4901 _z3_assert(s.ctx == r.ctx, "Context mismatch")
4902 ctx = d.ctx
4903 if len(sig) == 2:
4904 return ArraySortRef(Z3_mk_array_sort(ctx.ref(), d.ast, r.ast), ctx)
4905 dom = (Sort * arity)()
4906 for i in range(arity):
4907 dom[i] = sig[i].ast
4908 return ArraySortRef(Z3_mk_array_sort_n(ctx.ref(), arity, dom, r.ast), ctx)
4909
4910
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 9286 of file z3py.py.

9286def AtLeast(*args):
9287 """Create an at-least Pseudo-Boolean k constraint.
9288
9289 >>> a, b, c = Bools('a b c')
9290 >>> f = AtLeast(a, b, c, 2)
9291 """
9292 args = _get_args(args)
9293 if z3_debug():
9294 _z3_assert(len(args) > 1, "Non empty list of arguments expected")
9295 ctx = _ctx_from_ast_arg_list(args)
9296 if z3_debug():
9297 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
9298 args1 = _coerce_expr_list(args[:-1], ctx)
9299 k = args[-1]
9300 _args, sz = _to_ast_array(args1)
9301 return BoolRef(Z3_mk_atleast(ctx.ref(), sz, _args, k), ctx)
9302
9303
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 9268 of file z3py.py.

9268def AtMost(*args):
9269 """Create an at-most Pseudo-Boolean k constraint.
9270
9271 >>> a, b, c = Bools('a b c')
9272 >>> f = AtMost(a, b, c, 2)
9273 """
9274 args = _get_args(args)
9275 if z3_debug():
9276 _z3_assert(len(args) > 1, "Non empty list of arguments expected")
9277 ctx = _ctx_from_ast_arg_list(args)
9278 if z3_debug():
9279 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
9280 args1 = _coerce_expr_list(args[:-1], ctx)
9281 k = args[-1]
9282 _args, sz = _to_ast_array(args1)
9283 return BoolRef(Z3_mk_atmost(ctx.ref(), sz, _args, k), ctx)
9284
9285
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 4192 of file z3py.py.

4192def BitVec(name, bv, ctx=None):
4193 """Return a bit-vector constant named `name`. `bv` may be the number of bits of a bit-vector sort.
4194 If `ctx=None`, then the global context is used.
4195
4196 >>> x = BitVec('x', 16)
4197 >>> is_bv(x)
4198 True
4199 >>> x.size()
4200 16
4201 >>> x.sort()
4202 BitVec(16)
4203 >>> word = BitVecSort(16)
4204 >>> x2 = BitVec('x', word)
4205 >>> eq(x, x2)
4206 True
4207 """
4208 if isinstance(bv, BitVecSortRef):
4209 ctx = bv.ctx
4210 else:
4211 ctx = _get_ctx(ctx)
4212 bv = BitVecSort(bv, ctx)
4213 return BitVecRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), bv.ast), ctx)
4214
4215

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

4216def BitVecs(names, bv, ctx=None):
4217 """Return a tuple of bit-vector constants of size bv.
4218
4219 >>> x, y, z = BitVecs('x y z', 16)
4220 >>> x.size()
4221 16
4222 >>> x.sort()
4223 BitVec(16)
4224 >>> Sum(x, y, z)
4225 0 + x + y + z
4226 >>> Product(x, y, z)
4227 1*x*y*z
4228 >>> simplify(Product(x, y, z))
4229 x*y*z
4230 """
4231 ctx = _get_ctx(ctx)
4232 if isinstance(names, str):
4233 names = names.split(" ")
4234 return [BitVec(name, bv, ctx) for name in names]
4235
4236

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

4160def BitVecSort(sz, ctx=None):
4161 """Return a Z3 bit-vector sort of the given size. If `ctx=None`, then the global context is used.
4162
4163 >>> Byte = BitVecSort(8)
4164 >>> Word = BitVecSort(16)
4165 >>> Byte
4166 BitVec(8)
4167 >>> x = Const('x', Byte)
4168 >>> eq(x, BitVec('x', 8))
4169 True
4170 """
4171 ctx = _get_ctx(ctx)
4172 return BitVecSortRef(Z3_mk_bv_sort(ctx.ref(), sz), ctx)
4173
4174
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 4175 of file z3py.py.

4175def BitVecVal(val, bv, ctx=None):
4176 """Return a bit-vector value with the given number of bits. If `ctx=None`, then the global context is used.
4177
4178 >>> v = BitVecVal(10, 32)
4179 >>> v
4180 10
4181 >>> print("0x%.8x" % v.as_long())
4182 0x0000000a
4183 """
4184 if is_bv_sort(bv):
4185 ctx = bv.ctx
4186 return BitVecNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), bv.ast), ctx)
4187 else:
4188 ctx = _get_ctx(ctx)
4189 return BitVecNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), BitVecSort(bv, ctx).ast), ctx)
4190
4191
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 1864 of file z3py.py.

1864def Bool(name, ctx=None):
1865 """Return a Boolean constant named `name`. If `ctx=None`, then the global context is used.
1866
1867 >>> p = Bool('p')
1868 >>> q = Bool('q')
1869 >>> And(p, q)
1870 And(p, q)
1871 """
1872 ctx = _get_ctx(ctx)
1873 return BoolRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), BoolSort(ctx).ast), ctx)
1874
1875

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

1876def Bools(names, ctx=None):
1877 """Return a tuple of Boolean constants.
1878
1879 `names` is a single string containing all names separated by blank spaces.
1880 If `ctx=None`, then the global context is used.
1881
1882 >>> p, q, r = Bools('p q r')
1883 >>> And(p, Or(q, r))
1884 And(p, Or(q, r))
1885 """
1886 ctx = _get_ctx(ctx)
1887 if isinstance(names, str):
1888 names = names.split(" ")
1889 return [Bool(name, ctx) for name in names]
1890
1891

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

1827def BoolSort(ctx=None):
1828 """Return the Boolean Z3 sort. If `ctx=None`, then the global context is used.
1829
1830 >>> BoolSort()
1831 Bool
1832 >>> p = Const('p', BoolSort())
1833 >>> is_bool(p)
1834 True
1835 >>> r = Function('r', IntSort(), IntSort(), BoolSort())
1836 >>> r(0, 1)
1837 r(0, 1)
1838 >>> is_bool(r(0, 1))
1839 True
1840 """
1841 ctx = _get_ctx(ctx)
1842 return BoolSortRef(Z3_mk_bool_sort(ctx.ref()), ctx)
1843
1844
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 1845 of file z3py.py.

1845def BoolVal(val, ctx=None):
1846 """Return the Boolean value `True` or `False`. If `ctx=None`, then the global context is used.
1847
1848 >>> BoolVal(True)
1849 True
1850 >>> is_true(BoolVal(True))
1851 True
1852 >>> is_true(True)
1853 False
1854 >>> is_false(BoolVal(False))
1855 True
1856 """
1857 ctx = _get_ctx(ctx)
1858 if val:
1859 return BoolRef(Z3_mk_true(ctx.ref()), ctx)
1860 else:
1861 return BoolRef(Z3_mk_false(ctx.ref()), ctx)
1862
1863
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 1892 of file z3py.py.

1892def BoolVector(prefix, sz, ctx=None):
1893 """Return a list of Boolean constants of size `sz`.
1894
1895 The constants are named using the given prefix.
1896 If `ctx=None`, then the global context is used.
1897
1898 >>> P = BoolVector('p', 3)
1899 >>> P
1900 [p__0, p__1, p__2]
1901 >>> And(P)
1902 And(p__0, p__1, p__2)
1903 """
1904 return [Bool("%s__%s" % (prefix, i)) for i in range(sz)]
1905
1906

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

4128def BV2Int(a, is_signed=False):
4129 """Return the Z3 expression BV2Int(a).
4130
4131 >>> b = BitVec('b', 3)
4132 >>> BV2Int(b).sort()
4133 Int
4134 >>> x = Int('x')
4135 >>> x > BV2Int(b)
4136 x > BV2Int(b)
4137 >>> x > BV2Int(b, is_signed=False)
4138 x > BV2Int(b)
4139 >>> x > BV2Int(b, is_signed=True)
4140 x > If(b < 0, BV2Int(b) - 8, BV2Int(b))
4141 >>> solve(x > BV2Int(b), b == 1, x < 3)
4142 [x = 2, b = 1]
4143 """
4144 if z3_debug():
4145 _z3_assert(is_bv(a), "First argument must be a Z3 bit-vector expression")
4146 ctx = a.ctx
4147 # investigate problem with bv2int
4148 return ArithRef(Z3_mk_bv2int(ctx.ref(), a.as_ast(), is_signed), ctx)
4149
4150
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 4637 of file z3py.py.

4637def BVAddNoOverflow(a, b, signed):
4638 """A predicate the determines that bit-vector addition does not overflow"""
4639 _check_bv_args(a, b)
4640 a, b = _coerce_exprs(a, b)
4641 return BoolRef(Z3_mk_bvadd_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast(), signed), a.ctx)
4642
4643
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 4644 of file z3py.py.

4644def BVAddNoUnderflow(a, b):
4645 """A predicate the determines that signed bit-vector addition does not underflow"""
4646 _check_bv_args(a, b)
4647 a, b = _coerce_exprs(a, b)
4648 return BoolRef(Z3_mk_bvadd_no_underflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4649
4650
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 4679 of file z3py.py.

4679def BVMulNoOverflow(a, b, signed):
4680 """A predicate the determines that bit-vector multiplication does not overflow"""
4681 _check_bv_args(a, b)
4682 a, b = _coerce_exprs(a, b)
4683 return BoolRef(Z3_mk_bvmul_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast(), signed), a.ctx)
4684
4685
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 4686 of file z3py.py.

4686def BVMulNoUnderflow(a, b):
4687 """A predicate the determines that bit-vector signed multiplication does not underflow"""
4688 _check_bv_args(a, b)
4689 a, b = _coerce_exprs(a, b)
4690 return BoolRef(Z3_mk_bvmul_no_underflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4691
4692
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 4623 of file z3py.py.

4623def BVRedAnd(a):
4624 """Return the reduction-and expression of `a`."""
4625 if z3_debug():
4626 _z3_assert(is_bv(a), "First argument must be a Z3 bit-vector expression")
4627 return BitVecRef(Z3_mk_bvredand(a.ctx_ref(), a.as_ast()), a.ctx)
4628
4629
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 4630 of file z3py.py.

4630def BVRedOr(a):
4631 """Return the reduction-or expression of `a`."""
4632 if z3_debug():
4633 _z3_assert(is_bv(a), "First argument must be a Z3 bit-vector expression")
4634 return BitVecRef(Z3_mk_bvredor(a.ctx_ref(), a.as_ast()), a.ctx)
4635
4636
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 4665 of file z3py.py.

4665def BVSDivNoOverflow(a, b):
4666 """A predicate the determines that bit-vector signed division does not overflow"""
4667 _check_bv_args(a, b)
4668 a, b = _coerce_exprs(a, b)
4669 return BoolRef(Z3_mk_bvsdiv_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4670
4671
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 4672 of file z3py.py.

4672def BVSNegNoOverflow(a):
4673 """A predicate the determines that bit-vector unary negation does not overflow"""
4674 if z3_debug():
4675 _z3_assert(is_bv(a), "First argument must be a Z3 bit-vector expression")
4676 return BoolRef(Z3_mk_bvneg_no_overflow(a.ctx_ref(), a.as_ast()), a.ctx)
4677
4678
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 4651 of file z3py.py.

4651def BVSubNoOverflow(a, b):
4652 """A predicate the determines that bit-vector subtraction does not overflow"""
4653 _check_bv_args(a, b)
4654 a, b = _coerce_exprs(a, b)
4655 return BoolRef(Z3_mk_bvsub_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4656
4657
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 4658 of file z3py.py.

4658def BVSubNoUnderflow(a, b, signed):
4659 """A predicate the determines that bit-vector subtraction does not underflow"""
4660 _check_bv_args(a, b)
4661 a, b = _coerce_exprs(a, b)
4662 return BoolRef(Z3_mk_bvsub_no_underflow(a.ctx_ref(), a.as_ast(), b.as_ast(), signed), a.ctx)
4663
4664
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 3574 of file z3py.py.

3574def Cbrt(a, ctx=None):
3575 """ Return a Z3 expression which represents the cubic root of a.
3576
3577 >>> x = Real('x')
3578 >>> Cbrt(x)
3579 x**(1/3)
3580 """
3581 if not is_expr(a):
3582 ctx = _get_ctx(ctx)
3583 a = RealVal(a, ctx)
3584 return a ** "1/3"
3585

◆ CharFromBv()

CharFromBv (   bv)

Definition at line 11200 of file z3py.py.

11200def CharFromBv(bv):
11201 if not is_expr(bv):
11202 raise Z3Exception("Bit-vector expression needed")
11203 return _to_expr_ref(Z3_mk_char_from_bv(bv.ctx_ref(), bv.as_ast()), bv.ctx)
11204
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 11213 of file z3py.py.

11213def CharIsDigit(ch, ctx=None):
11214 ch = _coerce_char(ch, ctx)
11215 return ch.is_digit()
11216

◆ CharSort()

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

Definition at line 11096 of file z3py.py.

11096def CharSort(ctx=None):
11097 """Create a character sort
11098 >>> ch = CharSort()
11099 >>> print(ch)
11100 Char
11101 """
11102 ctx = _get_ctx(ctx)
11103 return CharSortRef(Z3_mk_char_sort(ctx.ref()), ctx)
11104
11105
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 11205 of file z3py.py.

11205def CharToBv(ch, ctx=None):
11206 ch = _coerce_char(ch, ctx)
11207 return ch.to_bv()
11208

◆ CharToInt()

CharToInt (   ch,
  ctx = None 
)

Definition at line 11209 of file z3py.py.

11209def CharToInt(ch, ctx=None):
11210 ch = _coerce_char(ch, ctx)
11211 return ch.to_int()
11212

◆ CharVal()

CharVal (   ch,
  ctx = None 
)

Definition at line 11192 of file z3py.py.

11192def CharVal(ch, ctx=None):
11193 ctx = _get_ctx(ctx)
11194 if isinstance(ch, str):
11195 ch = ord(ch)
11196 if not isinstance(ch, int):
11197 raise Z3Exception("character value should be an ordinal")
11198 return _to_expr_ref(Z3_mk_char(ctx.ref(), ch), ctx)
11199
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 11642 of file z3py.py.

11642def Complement(re):
11643 """Create the complement regular expression."""
11644 return ReRef(Z3_mk_re_complement(re.ctx_ref(), re.as_ast()), re.ctx)
11645
11646
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 4237 of file z3py.py.

4237def Concat(*args):
4238 """Create a Z3 bit-vector concatenation expression.
4239
4240 >>> v = BitVecVal(1, 4)
4241 >>> Concat(v, v+1, v)
4242 Concat(Concat(1, 1 + 1), 1)
4243 >>> simplify(Concat(v, v+1, v))
4244 289
4245 >>> print("%.3x" % simplify(Concat(v, v+1, v)).as_long())
4246 121
4247 """
4248 args = _get_args(args)
4249 sz = len(args)
4250 if z3_debug():
4251 _z3_assert(sz >= 2, "At least two arguments expected.")
4252
4253 ctx = None
4254 for a in args:
4255 if is_expr(a):
4256 ctx = a.ctx
4257 break
4258 if is_seq(args[0]) or isinstance(args[0], str):
4259 args = [_coerce_seq(s, ctx) for s in args]
4260 if z3_debug():
4261 _z3_assert(all([is_seq(a) for a in args]), "All arguments must be sequence expressions.")
4262 v = (Ast * sz)()
4263 for i in range(sz):
4264 v[i] = args[i].as_ast()
4265 return SeqRef(Z3_mk_seq_concat(ctx.ref(), sz, v), ctx)
4266
4267 if is_re(args[0]):
4268 if z3_debug():
4269 _z3_assert(all([is_re(a) for a in args]), "All arguments must be regular expressions.")
4270 v = (Ast * sz)()
4271 for i in range(sz):
4272 v[i] = args[i].as_ast()
4273 return ReRef(Z3_mk_re_concat(ctx.ref(), sz, v), ctx)
4274
4275 if z3_debug():
4276 _z3_assert(all([is_bv(a) for a in args]), "All arguments must be Z3 bit-vector expressions.")
4277 r = args[0]
4278 for i in range(sz - 1):
4279 r = BitVecRef(Z3_mk_concat(ctx.ref(), r.as_ast(), args[i + 1].as_ast()), ctx)
4280 return r
4281
4282
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 9085 of file z3py.py.

9085def Cond(p, t1, t2, ctx=None):
9086 """Return a tactic that applies tactic `t1` to a goal if probe `p` evaluates to true, and `t2` otherwise.
9087
9088 >>> t = Cond(Probe('is-qfnra'), Tactic('qfnra'), Tactic('smt'))
9089 """
9090 p = _to_probe(p, ctx)
9091 t1 = _to_tactic(t1, ctx)
9092 t2 = _to_tactic(t2, ctx)
9093 return Tactic(Z3_tactic_cond(t1.ctx.ref(), p.probe, t1.tactic, t2.tactic), t1.ctx)
9094
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 1543 of file z3py.py.

1543def Const(name, sort):
1544 """Create a constant of the given sort.
1545
1546 >>> Const('x', IntSort())
1547 x
1548 """
1549 if z3_debug():
1550 _z3_assert(isinstance(sort, SortRef), "Z3 sort expected")
1551 ctx = sort.ctx
1552 return _to_expr_ref(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), sort.ast), ctx)
1553
1554

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

1555def Consts(names, sort):
1556 """Create several constants of the given sort.
1557
1558 `names` is a string containing the names of all constants to be created.
1559 Blank spaces separate the names of different constants.
1560
1561 >>> x, y, z = Consts('x y z', IntSort())
1562 >>> x + y + z
1563 x + y + z
1564 """
1565 if isinstance(names, str):
1566 names = names.split(" ")
1567 return [Const(name, sort) for name in names]
1568
1569

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

11387def Contains(a, b):
11388 """Check if 'a' contains 'b'
11389 >>> s1 = Contains("abc", "ab")
11390 >>> simplify(s1)
11391 True
11392 >>> s2 = Contains("abc", "bc")
11393 >>> simplify(s2)
11394 True
11395 >>> x, y, z = Strings('x y z')
11396 >>> s3 = Contains(Concat(x,y,z), y)
11397 >>> simplify(s3)
11398 True
11399 """
11400 ctx = _get_ctx2(a, b)
11401 a = _coerce_seq(a, ctx)
11402 b = _coerce_seq(b, ctx)
11403 return BoolRef(Z3_mk_seq_contains(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
11404
11405
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 5329 of file z3py.py.

5329def CreateDatatypes(*ds):
5330 """Create mutually recursive Z3 datatypes using 1 or more Datatype helper objects.
5331
5332 In the following example we define a Tree-List using two mutually recursive datatypes.
5333
5334 >>> TreeList = Datatype('TreeList')
5335 >>> Tree = Datatype('Tree')
5336 >>> # Tree has two constructors: leaf and node
5337 >>> Tree.declare('leaf', ('val', IntSort()))
5338 >>> # a node contains a list of trees
5339 >>> Tree.declare('node', ('children', TreeList))
5340 >>> TreeList.declare('nil')
5341 >>> TreeList.declare('cons', ('car', Tree), ('cdr', TreeList))
5342 >>> Tree, TreeList = CreateDatatypes(Tree, TreeList)
5343 >>> Tree.val(Tree.leaf(10))
5344 val(leaf(10))
5345 >>> simplify(Tree.val(Tree.leaf(10)))
5346 10
5347 >>> n1 = Tree.node(TreeList.cons(Tree.leaf(10), TreeList.cons(Tree.leaf(20), TreeList.nil)))
5348 >>> n1
5349 node(cons(leaf(10), cons(leaf(20), nil)))
5350 >>> n2 = Tree.node(TreeList.cons(n1, TreeList.nil))
5351 >>> simplify(n2 == n1)
5352 False
5353 >>> simplify(TreeList.car(Tree.children(n2)) == n1)
5354 True
5355 """
5356 ds = _get_args(ds)
5357 if z3_debug():
5358 _z3_assert(len(ds) > 0, "At least one Datatype must be specified")
5359 _z3_assert(all([isinstance(d, Datatype) for d in ds]), "Arguments must be Datatypes")
5360 _z3_assert(all([d.ctx == ds[0].ctx for d in ds]), "Context mismatch")
5361 _z3_assert(all([d.constructors != [] for d in ds]), "Non-empty Datatypes expected")
5362 ctx = ds[0].ctx
5363 num = len(ds)
5364 names = (Symbol * num)()
5365 out = (Sort * num)()
5366 clists = (ConstructorList * num)()
5367 to_delete = []
5368 for i in range(num):
5369 d = ds[i]
5370 names[i] = to_symbol(d.name, ctx)
5371 num_cs = len(d.constructors)
5372 cs = (Constructor * num_cs)()
5373 for j in range(num_cs):
5374 c = d.constructors[j]
5375 cname = to_symbol(c[0], ctx)
5376 rname = to_symbol(c[1], ctx)
5377 fs = c[2]
5378 num_fs = len(fs)
5379 fnames = (Symbol * num_fs)()
5380 sorts = (Sort * num_fs)()
5381 refs = (ctypes.c_uint * num_fs)()
5382 for k in range(num_fs):
5383 fname = fs[k][0]
5384 ftype = fs[k][1]
5385 fnames[k] = to_symbol(fname, ctx)
5386 if isinstance(ftype, Datatype):
5387 if z3_debug():
5388 _z3_assert(
5389 ds.count(ftype) == 1,
5390 "One and only one occurrence of each datatype is expected",
5391 )
5392 sorts[k] = None
5393 refs[k] = ds.index(ftype)
5394 else:
5395 if z3_debug():
5396 _z3_assert(is_sort(ftype), "Z3 sort expected")
5397 sorts[k] = ftype.ast
5398 refs[k] = 0
5399 cs[j] = Z3_mk_constructor(ctx.ref(), cname, rname, num_fs, fnames, sorts, refs)
5400 to_delete.append(ScopedConstructor(cs[j], ctx))
5401 clists[i] = Z3_mk_constructor_list(ctx.ref(), num_cs, cs)
5402 to_delete.append(ScopedConstructorList(clists[i], ctx))
5403 Z3_mk_datatypes(ctx.ref(), num, names, out, clists)
5404 result = []
5405 # Create a field for every constructor, recognizer and accessor
5406 for i in range(num):
5407 dref = DatatypeSortRef(out[i], ctx)
5408 num_cs = dref.num_constructors()
5409 for j in range(num_cs):
5410 cref = dref.constructor(j)
5411 cref_name = cref.name()
5412 cref_arity = cref.arity()
5413 if cref.arity() == 0:
5414 cref = cref()
5415 setattr(dref, cref_name, cref)
5416 rref = dref.recognizer(j)
5417 setattr(dref, "is_" + cref_name, rref)
5418 for k in range(cref_arity):
5419 aref = dref.accessor(j, k)
5420 setattr(dref, aref.name(), aref)
5421 result.append(dref)
5422 return tuple(result)
5423
5424
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 5529 of file z3py.py.

5529def DatatypeSort(name, params=None, ctx=None):
5530 """Create a reference to a sort that was declared, or will be declared, as a recursive datatype.
5531
5532 Args:
5533 name: name of the datatype sort
5534 params: optional list/tuple of sort parameters for parametric datatypes
5535 ctx: Z3 context (optional)
5536
5537 Example:
5538 >>> # Non-parametric datatype
5539 >>> TreeRef = DatatypeSort('Tree')
5540 >>> # Parametric datatype with one parameter
5541 >>> ListIntRef = DatatypeSort('List', [IntSort()])
5542 >>> # Parametric datatype with multiple parameters
5543 >>> PairRef = DatatypeSort('Pair', [IntSort(), BoolSort()])
5544 """
5545 ctx = _get_ctx(ctx)
5546 if params is None or len(params) == 0:
5547 return DatatypeSortRef(Z3_mk_datatype_sort(ctx.ref(), to_symbol(name, ctx), 0, (Sort * 0)()), ctx)
5548 else:
5549 _params = (Sort * len(params))()
5550 for i in range(len(params)):
5551 _params[i] = params[i].ast
5552 return DatatypeSortRef(Z3_mk_datatype_sort(ctx.ref(), to_symbol(name, ctx), len(params), _params), ctx)
5553
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 733 of file z3py.py.

733def DeclareSort(name, ctx= None) -> SortRef:
734 """Create a new uninterpreted sort named `name`.
735
736 If `ctx=None`, then the new sort is declared in the global Z3Py context.
737
738 >>> A = DeclareSort('A')
739 >>> a = Const('a', A)
740 >>> b = Const('b', A)
741 >>> a.sort() == A
742 True
743 >>> b.sort() == A
744 True
745 >>> a == b
746 a == b
747 """
748 ctx = _get_ctx(ctx)
749 return SortRef(Z3_mk_uninterpreted_sort(ctx.ref(), to_symbol(name, ctx)), ctx)
750
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 761 of file z3py.py.

761def DeclareTypeVar(name, ctx=None):
762 """Create a new type variable named `name`.
763
764 If `ctx=None`, then the new sort is declared in the global Z3Py context.
765
766 """
767 ctx = _get_ctx(ctx)
768 return TypeVarRef(Z3_mk_type_variable(ctx.ref(), to_symbol(name, ctx)), ctx)
769
770
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 4957 of file z3py.py.

4957def Default(a):
4958 """ Return a default value for array expression.
4959 >>> b = K(IntSort(), 1)
4960 >>> prove(Default(b) == 1)
4961 proved
4962 """
4963 if z3_debug():
4964 _z3_assert(is_array_sort(a), "First argument must be a Z3 array expression")
4965 return a.default()
4966
4967

◆ describe_probes()

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

Definition at line 9006 of file z3py.py.

9006def describe_probes():
9007 """Display a (tabular) description of all available probes in Z3."""
9008 if in_html_mode():
9009 even = True
9010 print('<table border="1" cellpadding="2" cellspacing="0">')
9011 for p in probes():
9012 if even:
9013 print('<tr style="background-color:#CFCFCF">')
9014 even = False
9015 else:
9016 print("<tr>")
9017 even = True
9018 print("<td>%s</td><td>%s</td></tr>" % (p, insert_line_breaks(probe_description(p), 40)))
9019 print("</table>")
9020 else:
9021 for p in probes():
9022 print("%s : %s" % (p, probe_description(p)))
9023
9024

◆ describe_tactics()

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

Definition at line 8800 of file z3py.py.

8800def describe_tactics():
8801 """Display a (tabular) description of all available tactics in Z3."""
8802 if in_html_mode():
8803 even = True
8804 print('<table border="1" cellpadding="2" cellspacing="0">')
8805 for t in tactics():
8806 if even:
8807 print('<tr style="background-color:#CFCFCF">')
8808 even = False
8809 else:
8810 print("<tr>")
8811 even = True
8812 print("<td>%s</td><td>%s</td></tr>" % (t, insert_line_breaks(tactic_description(t), 40)))
8813 print("</table>")
8814 else:
8815 for t in tactics():
8816 print("%s : %s" % (t, tactic_description(t)))
8817
8818

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

1210def deserialize(st):
1211 """inverse function to the serialize method on ExprRef.
1212 It is made available to make it easier for users to serialize expressions back and forth between
1213 strings. Solvers can be serialized using the 'sexpr()' method.
1214 """
1215 s = Solver()
1216 s.from_string(st)
1217 if len(s.assertions()) != 1:
1218 raise Z3Exception("single assertion expected")
1219 fml = s.assertions()[0]
1220 if fml.num_args() != 1:
1221 raise Z3Exception("dummy function 'F' expected")
1222 return fml.arg(0)
1223

◆ Diff()

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

Definition at line 11692 of file z3py.py.

11692def Diff(a, b, ctx=None):
11693 """Create the difference regular expression
11694 """
11695 if z3_debug():
11696 _z3_assert(is_expr(a), "expression expected")
11697 _z3_assert(is_expr(b), "expression expected")
11698 return ReRef(Z3_mk_re_diff(a.ctx_ref(), a.ast, b.ast), a.ctx)
11699
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 5566 of file z3py.py.

5566def DisjointSum(name, sorts, ctx=None):
5567 """Create a named tagged union sort base on a set of underlying sorts
5568 Example:
5569 >>> sum, ((inject0, extract0), (inject1, extract1)) = DisjointSum("+", [IntSort(), StringSort()])
5570 """
5571 sum = Datatype(name, ctx)
5572 for i in range(len(sorts)):
5573 sum.declare("inject%d" % i, ("project%d" % i, sorts[i]))
5574 sum = sum.create()
5575 return sum, [(sum.constructor(i), sum.accessor(i, 0)) for i in range(len(sorts))]
5576
5577

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

1510def Distinct(*args):
1511 """Create a Z3 distinct expression.
1512
1513 >>> x = Int('x')
1514 >>> y = Int('y')
1515 >>> Distinct(x, y)
1516 x != y
1517 >>> z = Int('z')
1518 >>> Distinct(x, y, z)
1519 Distinct(x, y, z)
1520 >>> simplify(Distinct(x, y, z))
1521 Distinct(x, y, z)
1522 >>> simplify(Distinct(x, y, z), blast_distinct=True)
1523 And(Not(x == y), Not(x == z), Not(y == z))
1524 """
1525 args = _get_args(args)
1526 ctx = _ctx_from_ast_arg_list(args)
1527 if z3_debug():
1528 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
1529 args = _coerce_expr_list(args, ctx)
1530 _args, sz = _to_ast_array(args)
1531 return BoolRef(Z3_mk_distinct(ctx.ref(), sz, _args), ctx)
1532
1533
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 11317 of file z3py.py.

11317def Empty(s):
11318 """Create the empty sequence of the given sort
11319 >>> e = Empty(StringSort())
11320 >>> e2 = StringVal("")
11321 >>> print(e.eq(e2))
11322 True
11323 >>> e3 = Empty(SeqSort(IntSort()))
11324 >>> print(e3)
11325 Empty(Seq(Int))
11326 >>> e4 = Empty(ReSort(SeqSort(IntSort())))
11327 >>> print(e4)
11328 Empty(ReSort(Seq(Int)))
11329 """
11330 if isinstance(s, SeqSortRef):
11331 return SeqRef(Z3_mk_seq_empty(s.ctx_ref(), s.ast), s.ctx)
11332 if isinstance(s, ReSortRef):
11333 return ReRef(Z3_mk_re_empty(s.ctx_ref(), s.ast), s.ctx)
11334 raise Z3Exception("Non-sequence, non-regular expression sort passed to Empty")
11335
11336
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 5093 of file z3py.py.

5093def EmptySet(s):
5094 """Create the empty set
5095 >>> EmptySet(IntSort())
5096 K(Int, False)
5097 """
5098 ctx = s.ctx
5099 return ArrayRef(Z3_mk_empty_set(ctx.ref(), s.ast), ctx)
5100
5101
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 11811 of file z3py.py.

11811def ensure_prop_closures():
11812 global _prop_closures
11813 if _prop_closures is None:
11814 _prop_closures = PropClosures()
11815
11816

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

5578def EnumSort(name, values, ctx=None):
5579 """Return a new enumeration sort named `name` containing the given values.
5580
5581 The result is a pair (sort, list of constants).
5582 Example:
5583 >>> Color, (red, green, blue) = EnumSort('Color', ['red', 'green', 'blue'])
5584 """
5585 if z3_debug():
5586 _z3_assert(isinstance(name, str), "Name must be a string")
5587 _z3_assert(all([isinstance(v, str) for v in values]), "Enumeration sort values must be strings")
5588 _z3_assert(len(values) > 0, "At least one value expected")
5589 ctx = _get_ctx(ctx)
5590 num = len(values)
5591 _val_names = (Symbol * num)()
5592 for i in range(num):
5593 _val_names[i] = to_symbol(values[i], ctx)
5594 _values = (FuncDecl * num)()
5595 _testers = (FuncDecl * num)()
5596 name = to_symbol(name, ctx)
5597 S = DatatypeSortRef(Z3_mk_enumeration_sort(ctx.ref(), name, num, _val_names, _values, _testers), ctx)
5598 V = []
5599 for i in range(num):
5600 V.append(FuncDeclRef(_values[i], ctx))
5601 V = [a() for a in V]
5602 return S, V
5603
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 506 of file z3py.py.

506def eq(a : AstRef, b : AstRef) -> bool:
507 """Return `True` if `a` and `b` are structurally identical AST nodes.
508
509 >>> x = Int('x')
510 >>> y = Int('y')
511 >>> eq(x, y)
512 False
513 >>> eq(x + 1, x + 1)
514 True
515 >>> eq(x + 1, 1 + x)
516 False
517 >>> eq(simplify(x + 1), simplify(1 + x))
518 True
519 """
520 if z3_debug():
521 _z3_assert(is_ast(a) and is_ast(b), "Z3 ASTs expected")
522 return a.eq(b)
523
524

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

2386def Exists(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2387 """Create a Z3 exists formula.
2388
2389 The parameters `weight`, `qif`, `skid`, `patterns` and `no_patterns` are optional annotations.
2390
2391
2392 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2393 >>> x = Int('x')
2394 >>> y = Int('y')
2395 >>> q = Exists([x, y], f(x, y) >= x, skid="foo")
2396 >>> q
2397 Exists([x, y], f(x, y) >= x)
2398 >>> is_quantifier(q)
2399 True
2400 >>> r = Tactic('nnf')(q).as_expr()
2401 >>> is_quantifier(r)
2402 False
2403 """
2404 return _mk_quantifier(False, vs, body, weight, qid, skid, patterns, no_patterns)
2405
2406

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

5046def Ext(a, b):
5047 """Return extensionality index for one-dimensional arrays.
5048 >> a, b = Consts('a b', SetSort(IntSort()))
5049 >> Ext(a, b)
5050 Ext(a, b)
5051 """
5052 ctx = a.ctx
5053 if z3_debug():
5054 _z3_assert(is_array_sort(a) and (is_array(b) or b.is_lambda()), "arguments must be arrays")
5055 return _to_expr_ref(Z3_mk_array_ext(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
5056
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 4283 of file z3py.py.

4283def Extract(high, low, a):
4284 """Create a Z3 bit-vector extraction expression or sequence extraction expression.
4285
4286 Extract is overloaded to work with both bit-vectors and sequences:
4287
4288 **Bit-vector extraction**: Extract(high, low, bitvector)
4289 Extracts bits from position `high` down to position `low` (both inclusive).
4290 - high: int - the highest bit position to extract (0-indexed from right)
4291 - low: int - the lowest bit position to extract (0-indexed from right)
4292 - bitvector: BitVecRef - the bit-vector to extract from
4293 Returns a new bit-vector containing bits [high:low]
4294
4295 **Sequence extraction**: Extract(sequence, offset, length)
4296 Extracts a subsequence starting at the given offset with the specified length.
4297 The functions SubString and SubSeq are redirected to this form of Extract.
4298 - sequence: SeqRef or str - the sequence to extract from
4299 - offset: int - the starting position (0-indexed)
4300 - length: int - the number of elements to extract
4301 Returns a new sequence containing the extracted subsequence
4302
4303 >>> # Bit-vector extraction examples
4304 >>> x = BitVec('x', 8)
4305 >>> Extract(6, 2, x) # Extract bits 6 down to 2 (5 bits total)
4306 Extract(6, 2, x)
4307 >>> Extract(6, 2, x).sort() # Result is a 5-bit vector
4308 BitVec(5)
4309 >>> Extract(7, 0, x) # Extract all 8 bits
4310 Extract(7, 0, x)
4311 >>> Extract(3, 3, x) # Extract single bit at position 3
4312 Extract(3, 3, x)
4313
4314 >>> # Sequence extraction examples
4315 >>> s = StringVal("hello")
4316 >>> Extract(s, 1, 3) # Extract 3 characters starting at position 1
4317 str.substr("hello", 1, 3)
4318 >>> simplify(Extract(StringVal("abcd"), 2, 1)) # Extract 1 character at position 2
4319 "c"
4320 >>> simplify(Extract(StringVal("abcd"), 0, 2)) # Extract first 2 characters
4321 "ab"
4322 """
4323 if isinstance(high, str):
4324 high = StringVal(high)
4325 if is_seq(high):
4326 s = high
4327 offset, length = _coerce_exprs(low, a, s.ctx)
4328 return SeqRef(Z3_mk_seq_extract(s.ctx_ref(), s.as_ast(), offset.as_ast(), length.as_ast()), s.ctx)
4329 if z3_debug():
4330 _z3_assert(low <= high, "First argument must be greater than or equal to second argument")
4331 _z3_assert(_is_int(high) and high >= 0 and _is_int(low) and low >= 0,
4332 "First and second arguments must be non negative integers")
4333 _z3_assert(is_bv(a), "Third argument must be a Z3 bit-vector expression")
4334 return BitVecRef(Z3_mk_extract(a.ctx_ref(), high, low, a.as_ast()), a.ctx)
4335
4336
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 9043 of file z3py.py.

9043def FailIf(p, ctx=None):
9044 """Return a tactic that fails if the probe `p` evaluates to true.
9045 Otherwise, it returns the input goal unmodified.
9046
9047 In the following example, the tactic applies 'simplify' if and only if there are
9048 more than 2 constraints in the goal.
9049
9050 >>> t = OrElse(FailIf(Probe('size') > 2), Tactic('simplify'))
9051 >>> x, y = Ints('x y')
9052 >>> g = Goal()
9053 >>> g.add(x > 0)
9054 >>> g.add(y > 0)
9055 >>> t(g)
9056 [[x > 0, y > 0]]
9057 >>> g.add(x == y + 1)
9058 >>> t(g)
9059 [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
9060 """
9061 p = _to_probe(p, ctx)
9062 return Tactic(Z3_tactic_fail_if(p.ctx.ref(), p.probe), p.ctx)
9063
9064
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 7974 of file z3py.py.

7974def FiniteDomainSort(name, sz, ctx=None):
7975 """Create a named finite domain sort of a given size sz"""
7976 if not isinstance(name, Symbol):
7977 name = to_symbol(name)
7978 ctx = _get_ctx(ctx)
7979 return FiniteDomainSortRef(Z3_mk_finite_domain_sort(ctx.ref(), name, sz), ctx)
7980
7981
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 8044 of file z3py.py.

8044def FiniteDomainVal(val, sort, ctx=None):
8045 """Return a Z3 finite-domain value. If `ctx=None`, then the global context is used.
8046
8047 >>> s = FiniteDomainSort('S', 256)
8048 >>> FiniteDomainVal(255, s)
8049 255
8050 >>> FiniteDomainVal('100', s)
8051 100
8052 """
8053 if z3_debug():
8054 _z3_assert(is_finite_domain_sort(sort), "Expected finite-domain sort")
8055 ctx = sort.ctx
8056 return FiniteDomainNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), sort.ast), ctx)
8057
8058

◆ Float128()

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

Definition at line 9771 of file z3py.py.

9771def Float128(ctx=None):
9772 """Floating-point 128-bit (quadruple) sort."""
9773 ctx = _get_ctx(ctx)
9774 return FPSortRef(Z3_mk_fpa_sort_128(ctx.ref()), ctx)
9775
9776
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 9735 of file z3py.py.

9735def Float16(ctx=None):
9736 """Floating-point 16-bit (half) sort."""
9737 ctx = _get_ctx(ctx)
9738 return FPSortRef(Z3_mk_fpa_sort_16(ctx.ref()), ctx)
9739
9740
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 9747 of file z3py.py.

9747def Float32(ctx=None):
9748 """Floating-point 32-bit (single) sort."""
9749 ctx = _get_ctx(ctx)
9750 return FPSortRef(Z3_mk_fpa_sort_32(ctx.ref()), ctx)
9751
9752
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 9759 of file z3py.py.

9759def Float64(ctx=None):
9760 """Floating-point 64-bit (double) sort."""
9761 ctx = _get_ctx(ctx)
9762 return FPSortRef(Z3_mk_fpa_sort_64(ctx.ref()), ctx)
9763
9764
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 9765 of file z3py.py.

9765def FloatDouble(ctx=None):
9766 """Floating-point 64-bit (double) sort."""
9767 ctx = _get_ctx(ctx)
9768 return FPSortRef(Z3_mk_fpa_sort_double(ctx.ref()), ctx)
9769
9770
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 9741 of file z3py.py.

9741def FloatHalf(ctx=None):
9742 """Floating-point 16-bit (half) sort."""
9743 ctx = _get_ctx(ctx)
9744 return FPSortRef(Z3_mk_fpa_sort_half(ctx.ref()), ctx)
9745
9746
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 9777 of file z3py.py.

9777def FloatQuadruple(ctx=None):
9778 """Floating-point 128-bit (quadruple) sort."""
9779 ctx = _get_ctx(ctx)
9780 return FPSortRef(Z3_mk_fpa_sort_quadruple(ctx.ref()), ctx)
9781
9782
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 9753 of file z3py.py.

9753def FloatSingle(ctx=None):
9754 """Floating-point 32-bit (single) sort."""
9755 ctx = _get_ctx(ctx)
9756 return FPSortRef(Z3_mk_fpa_sort_single(ctx.ref()), ctx)
9757
9758
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 2368 of file z3py.py.

2368def ForAll(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2369 """Create a Z3 forall formula.
2370
2371 The parameters `weight`, `qid`, `skid`, `patterns` and `no_patterns` are optional annotations.
2372
2373 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2374 >>> x = Int('x')
2375 >>> y = Int('y')
2376 >>> ForAll([x, y], f(x, y) >= x)
2377 ForAll([x, y], f(x, y) >= x)
2378 >>> ForAll([x, y], f(x, y) >= x, patterns=[ f(x, y) ])
2379 ForAll([x, y], f(x, y) >= x)
2380 >>> ForAll([x, y], f(x, y) >= x, weight=10)
2381 ForAll([x, y], f(x, y) >= x)
2382 """
2383 return _mk_quantifier(True, vs, body, weight, qid, skid, patterns, no_patterns)
2384
2385

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

10413def FP(name, fpsort, ctx=None):
10414 """Return a floating-point constant named `name`.
10415 `fpsort` is the floating-point sort.
10416 If `ctx=None`, then the global context is used.
10417
10418 >>> x = FP('x', FPSort(8, 24))
10419 >>> is_fp(x)
10420 True
10421 >>> x.ebits()
10422 8
10423 >>> x.sort()
10424 FPSort(8, 24)
10425 >>> word = FPSort(8, 24)
10426 >>> x2 = FP('x', word)
10427 >>> eq(x, x2)
10428 True
10429 """
10430 if isinstance(fpsort, FPSortRef) and ctx is None:
10431 ctx = fpsort.ctx
10432 else:
10433 ctx = _get_ctx(ctx)
10434 return FPRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), fpsort.ast), ctx)
10435
10436

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

10456def fpAbs(a, ctx=None):
10457 """Create a Z3 floating-point absolute value expression.
10458
10459 >>> s = FPSort(8, 24)
10460 >>> rm = RNE()
10461 >>> x = FPVal(1.0, s)
10462 >>> fpAbs(x)
10463 fpAbs(1)
10464 >>> y = FPVal(-20.0, s)
10465 >>> y
10466 -1.25*(2**4)
10467 >>> fpAbs(y)
10468 fpAbs(-1.25*(2**4))
10469 >>> fpAbs(-1.25*(2**4))
10470 fpAbs(-1.25*(2**4))
10471 >>> fpAbs(x).sort()
10472 FPSort(8, 24)
10473 """
10474 ctx = _get_ctx(ctx)
10475 [a] = _coerce_fp_expr_list([a], ctx)
10476 return FPRef(Z3_mk_fpa_abs(ctx.ref(), a.as_ast()), ctx)
10477
10478
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 10547 of file z3py.py.

10547def fpAdd(rm, a, b, ctx=None):
10548 """Create a Z3 floating-point addition expression.
10549
10550 >>> s = FPSort(8, 24)
10551 >>> rm = RNE()
10552 >>> x = FP('x', s)
10553 >>> y = FP('y', s)
10554 >>> fpAdd(rm, x, y)
10555 x + y
10556 >>> fpAdd(RTZ(), x, y) # default rounding mode is RTZ
10557 fpAdd(RTZ(), x, y)
10558 >>> fpAdd(rm, x, y).sort()
10559 FPSort(8, 24)
10560 """
10561 return _mk_fp_bin(Z3_mk_fpa_add, rm, a, b, ctx)
10562
10563

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

10869def fpBVToFP(v, sort, ctx=None):
10870 """Create a Z3 floating-point conversion expression that represents the
10871 conversion from a bit-vector term to a floating-point term.
10872
10873 >>> x_bv = BitVecVal(0x3F800000, 32)
10874 >>> x_fp = fpBVToFP(x_bv, Float32())
10875 >>> x_fp
10876 fpToFP(1065353216)
10877 >>> simplify(x_fp)
10878 1
10879 """
10880 _z3_assert(is_bv(v), "First argument must be a Z3 bit-vector expression")
10881 _z3_assert(is_fp_sort(sort), "Second argument must be a Z3 floating-point sort.")
10882 ctx = _get_ctx(ctx)
10883 return FPRef(Z3_mk_fpa_to_fp_bv(ctx.ref(), v.ast, sort.ast), ctx)
10884
10885
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 10594 of file z3py.py.

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

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

10777def fpEQ(a, b, ctx=None):
10778 """Create the Z3 floating-point expression `fpEQ(other, self)`.
10779
10780 >>> x, y = FPs('x y', FPSort(8, 24))
10781 >>> fpEQ(x, y)
10782 fpEQ(x, y)
10783 >>> fpEQ(x, y).sexpr()
10784 '(fp.eq x y)'
10785 """
10786 return _mk_fp_bin_pred(Z3_mk_fpa_eq, a, b, ctx)
10787
10788

◆ fpFMA()

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

Definition at line 10653 of file z3py.py.

10653def fpFMA(rm, a, b, c, ctx=None):
10654 """Create a Z3 floating-point fused multiply-add expression.
10655 """
10656 return _mk_fp_tern(Z3_mk_fpa_fma, rm, a, b, c, ctx)
10657
10658

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

10801def fpFP(sgn, exp, sig, ctx=None):
10802 """Create the Z3 floating-point value `fpFP(sgn, sig, exp)` from the three bit-vectors sgn, sig, and exp.
10803
10804 >>> s = FPSort(8, 24)
10805 >>> x = fpFP(BitVecVal(1, 1), BitVecVal(2**7-1, 8), BitVecVal(2**22, 23))
10806 >>> print(x)
10807 fpFP(1, 127, 4194304)
10808 >>> xv = FPVal(-1.5, s)
10809 >>> print(xv)
10810 -1.5
10811 >>> slvr = Solver()
10812 >>> slvr.add(fpEQ(x, xv))
10813 >>> slvr.check()
10814 sat
10815 >>> xv = FPVal(+1.5, s)
10816 >>> print(xv)
10817 1.5
10818 >>> slvr = Solver()
10819 >>> slvr.add(fpEQ(x, xv))
10820 >>> slvr.check()
10821 unsat
10822 """
10823 _z3_assert(is_bv(sgn) and is_bv(exp) and is_bv(sig), "sort mismatch")
10824 _z3_assert(sgn.sort().size() == 1, "sort mismatch")
10825 ctx = _get_ctx(ctx)
10826 _z3_assert(ctx == sgn.ctx == exp.ctx == sig.ctx, "context mismatch")
10827 return FPRef(Z3_mk_fpa_fp(ctx.ref(), sgn.ast, exp.ast, sig.ast), ctx)
10828
10829
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 10886 of file z3py.py.

10886def fpFPToFP(rm, v, sort, ctx=None):
10887 """Create a Z3 floating-point conversion expression that represents the
10888 conversion from a floating-point term to a floating-point term of different precision.
10889
10890 >>> x_sgl = FPVal(1.0, Float32())
10891 >>> x_dbl = fpFPToFP(RNE(), x_sgl, Float64())
10892 >>> x_dbl
10893 fpToFP(RNE(), 1)
10894 >>> simplify(x_dbl)
10895 1
10896 >>> x_dbl.sort()
10897 FPSort(11, 53)
10898 """
10899 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10900 _z3_assert(is_fp(v), "Second argument must be a Z3 floating-point expression.")
10901 _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
10902 ctx = _get_ctx(ctx)
10903 return FPRef(Z3_mk_fpa_to_fp_float(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
10904
10905
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 10765 of file z3py.py.

10765def fpGEQ(a, b, ctx=None):
10766 """Create the Z3 floating-point expression `other >= self`.
10767
10768 >>> x, y = FPs('x y', FPSort(8, 24))
10769 >>> fpGEQ(x, y)
10770 x >= y
10771 >>> (x >= y).sexpr()
10772 '(fp.geq x y)'
10773 """
10774 return _mk_fp_bin_pred(Z3_mk_fpa_geq, a, b, ctx)
10775
10776

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

10753def fpGT(a, b, ctx=None):
10754 """Create the Z3 floating-point expression `other > self`.
10755
10756 >>> x, y = FPs('x y', FPSort(8, 24))
10757 >>> fpGT(x, y)
10758 x > y
10759 >>> (x > y).sexpr()
10760 '(fp.gt x y)'
10761 """
10762 return _mk_fp_bin_pred(Z3_mk_fpa_gt, a, b, ctx)
10763
10764

◆ fpInfinity()

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

Definition at line 10341 of file z3py.py.

10341def fpInfinity(s, negative):
10342 """Create a Z3 floating-point +oo or -oo term."""
10343 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10344 _z3_assert(isinstance(negative, bool), "expected Boolean flag")
10345 return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, negative), s.ctx)
10346
10347
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 10683 of file z3py.py.

10683def fpIsInf(a, ctx=None):
10684 """Create a Z3 floating-point isInfinite expression.
10685
10686 >>> s = FPSort(8, 24)
10687 >>> x = FP('x', s)
10688 >>> fpIsInf(x)
10689 fpIsInf(x)
10690 """
10691 return _mk_fp_unary_pred(Z3_mk_fpa_is_infinite, a, ctx)
10692
10693

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

10671def fpIsNaN(a, ctx=None):
10672 """Create a Z3 floating-point isNaN expression.
10673
10674 >>> s = FPSort(8, 24)
10675 >>> x = FP('x', s)
10676 >>> y = FP('y', s)
10677 >>> fpIsNaN(x)
10678 fpIsNaN(x)
10679 """
10680 return _mk_fp_unary_pred(Z3_mk_fpa_is_nan, a, ctx)
10681
10682

◆ fpIsNegative()

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

Definition at line 10712 of file z3py.py.

10712def fpIsNegative(a, ctx=None):
10713 """Create a Z3 floating-point isNegative expression.
10714 """
10715 return _mk_fp_unary_pred(Z3_mk_fpa_is_negative, a, ctx)
10716
10717

◆ fpIsNormal()

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

Definition at line 10700 of file z3py.py.

10700def fpIsNormal(a, ctx=None):
10701 """Create a Z3 floating-point isNormal expression.
10702 """
10703 return _mk_fp_unary_pred(Z3_mk_fpa_is_normal, a, ctx)
10704
10705

◆ fpIsPositive()

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

Definition at line 10718 of file z3py.py.

10718def fpIsPositive(a, ctx=None):
10719 """Create a Z3 floating-point isPositive expression.
10720 """
10721 return _mk_fp_unary_pred(Z3_mk_fpa_is_positive, a, ctx)
10722
10723

◆ fpIsSubnormal()

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

Definition at line 10706 of file z3py.py.

10706def fpIsSubnormal(a, ctx=None):
10707 """Create a Z3 floating-point isSubnormal expression.
10708 """
10709 return _mk_fp_unary_pred(Z3_mk_fpa_is_subnormal, a, ctx)
10710
10711

◆ fpIsZero()

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

Definition at line 10694 of file z3py.py.

10694def fpIsZero(a, ctx=None):
10695 """Create a Z3 floating-point isZero expression.
10696 """
10697 return _mk_fp_unary_pred(Z3_mk_fpa_is_zero, a, ctx)
10698
10699

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

10741def fpLEQ(a, b, ctx=None):
10742 """Create the Z3 floating-point expression `other <= self`.
10743
10744 >>> x, y = FPs('x y', FPSort(8, 24))
10745 >>> fpLEQ(x, y)
10746 x <= y
10747 >>> (x <= y).sexpr()
10748 '(fp.leq x y)'
10749 """
10750 return _mk_fp_bin_pred(Z3_mk_fpa_leq, a, b, ctx)
10751
10752

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

10729def fpLT(a, b, ctx=None):
10730 """Create the Z3 floating-point expression `other < self`.
10731
10732 >>> x, y = FPs('x y', FPSort(8, 24))
10733 >>> fpLT(x, y)
10734 x < y
10735 >>> (x < y).sexpr()
10736 '(fp.lt x y)'
10737 """
10738 return _mk_fp_bin_pred(Z3_mk_fpa_lt, a, b, ctx)
10739
10740

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

10638def fpMax(a, b, ctx=None):
10639 """Create a Z3 floating-point maximum expression.
10640
10641 >>> s = FPSort(8, 24)
10642 >>> rm = RNE()
10643 >>> x = FP('x', s)
10644 >>> y = FP('y', s)
10645 >>> fpMax(x, y)
10646 fpMax(x, y)
10647 >>> fpMax(x, y).sort()
10648 FPSort(8, 24)
10649 """
10650 return _mk_fp_bin_norm(Z3_mk_fpa_max, a, b, ctx)
10651
10652

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

10623def fpMin(a, b, ctx=None):
10624 """Create a Z3 floating-point minimum expression.
10625
10626 >>> s = FPSort(8, 24)
10627 >>> rm = RNE()
10628 >>> x = FP('x', s)
10629 >>> y = FP('y', s)
10630 >>> fpMin(x, y)
10631 fpMin(x, y)
10632 >>> fpMin(x, y).sort()
10633 FPSort(8, 24)
10634 """
10635 return _mk_fp_bin_norm(Z3_mk_fpa_min, a, b, ctx)
10636
10637

◆ fpMinusInfinity()

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

Definition at line 10335 of file z3py.py.

10335def fpMinusInfinity(s):
10336 """Create a Z3 floating-point -oo term."""
10337 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10338 return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, True), s.ctx)
10339
10340

◆ fpMinusZero()

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

Definition at line 10354 of file z3py.py.

10354def fpMinusZero(s):
10355 """Create a Z3 floating-point -0.0 term."""
10356 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10357 return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, True), s.ctx)
10358
10359
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 10579 of file z3py.py.

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

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

10301def fpNaN(s):
10302 """Create a Z3 floating-point NaN term.
10303
10304 >>> s = FPSort(8, 24)
10305 >>> set_fpa_pretty(True)
10306 >>> fpNaN(s)
10307 NaN
10308 >>> pb = get_fpa_pretty()
10309 >>> set_fpa_pretty(False)
10310 >>> fpNaN(s)
10311 fpNaN(FPSort(8, 24))
10312 >>> set_fpa_pretty(pb)
10313 """
10314 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10315 return FPNumRef(Z3_mk_fpa_nan(s.ctx_ref(), s.ast), s.ctx)
10316
10317
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 10479 of file z3py.py.

10479def fpNeg(a, ctx=None):
10480 """Create a Z3 floating-point addition expression.
10481
10482 >>> s = FPSort(8, 24)
10483 >>> rm = RNE()
10484 >>> x = FP('x', s)
10485 >>> fpNeg(x)
10486 -x
10487 >>> fpNeg(x).sort()
10488 FPSort(8, 24)
10489 """
10490 ctx = _get_ctx(ctx)
10491 [a] = _coerce_fp_expr_list([a], ctx)
10492 return FPRef(Z3_mk_fpa_neg(ctx.ref(), a.as_ast()), ctx)
10493
10494
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 10789 of file z3py.py.

10789def fpNEQ(a, b, ctx=None):
10790 """Create the Z3 floating-point expression `Not(fpEQ(other, self))`.
10791
10792 >>> x, y = FPs('x y', FPSort(8, 24))
10793 >>> fpNEQ(x, y)
10794 Not(fpEQ(x, y))
10795 >>> (x != y).sexpr()
10796 '(distinct x y)'
10797 """
10798 return Not(fpEQ(a, b, ctx))
10799
10800

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

10318def fpPlusInfinity(s):
10319 """Create a Z3 floating-point +oo term.
10320
10321 >>> s = FPSort(8, 24)
10322 >>> pb = get_fpa_pretty()
10323 >>> set_fpa_pretty(True)
10324 >>> fpPlusInfinity(s)
10325 +oo
10326 >>> set_fpa_pretty(False)
10327 >>> fpPlusInfinity(s)
10328 fpPlusInfinity(FPSort(8, 24))
10329 >>> set_fpa_pretty(pb)
10330 """
10331 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10332 return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, False), s.ctx)
10333
10334

◆ fpPlusZero()

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

Definition at line 10348 of file z3py.py.

10348def fpPlusZero(s):
10349 """Create a Z3 floating-point +0.0 term."""
10350 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10351 return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, False), s.ctx)
10352
10353

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

10906def fpRealToFP(rm, v, sort, ctx=None):
10907 """Create a Z3 floating-point conversion expression that represents the
10908 conversion from a real term to a floating-point term.
10909
10910 >>> x_r = RealVal(1.5)
10911 >>> x_fp = fpRealToFP(RNE(), x_r, Float32())
10912 >>> x_fp
10913 fpToFP(RNE(), 3/2)
10914 >>> simplify(x_fp)
10915 1.5
10916 """
10917 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10918 _z3_assert(is_real(v), "Second argument must be a Z3 expression or real sort.")
10919 _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
10920 ctx = _get_ctx(ctx)
10921 return FPRef(Z3_mk_fpa_to_fp_real(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
10922
10923
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 10609 of file z3py.py.

10609def fpRem(a, b, ctx=None):
10610 """Create a Z3 floating-point remainder expression.
10611
10612 >>> s = FPSort(8, 24)
10613 >>> x = FP('x', s)
10614 >>> y = FP('y', s)
10615 >>> fpRem(x, y)
10616 fpRem(x, y)
10617 >>> fpRem(x, y).sort()
10618 FPSort(8, 24)
10619 """
10620 return _mk_fp_bin_norm(Z3_mk_fpa_rem, a, b, ctx)
10621
10622

◆ fpRoundToIntegral()

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

Definition at line 10665 of file z3py.py.

10665def fpRoundToIntegral(rm, a, ctx=None):
10666 """Create a Z3 floating-point roundToIntegral expression.
10667 """
10668 return _mk_fp_unary(Z3_mk_fpa_round_to_integral, rm, a, ctx)
10669
10670

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

10437def FPs(names, fpsort, ctx=None):
10438 """Return an array of floating-point constants.
10439
10440 >>> x, y, z = FPs('x y z', FPSort(8, 24))
10441 >>> x.sort()
10442 FPSort(8, 24)
10443 >>> x.sbits()
10444 24
10445 >>> x.ebits()
10446 8
10447 >>> fpMul(RNE(), fpAdd(RNE(), x, y), z)
10448 (x + y) * z
10449 """
10450 ctx = _get_ctx(ctx)
10451 if isinstance(names, str):
10452 names = names.split(" ")
10453 return [FP(name, fpsort, ctx) for name in names]
10454
10455

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

10924def fpSignedToFP(rm, v, sort, ctx=None):
10925 """Create a Z3 floating-point conversion expression that represents the
10926 conversion from a signed bit-vector term (encoding an integer) to a floating-point term.
10927
10928 >>> x_signed = BitVecVal(-5, BitVecSort(32))
10929 >>> x_fp = fpSignedToFP(RNE(), x_signed, Float32())
10930 >>> x_fp
10931 fpToFP(RNE(), 4294967291)
10932 >>> simplify(x_fp)
10933 -1.25*(2**2)
10934 """
10935 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10936 _z3_assert(is_bv(v), "Second argument must be a Z3 bit-vector expression")
10937 _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
10938 ctx = _get_ctx(ctx)
10939 return FPRef(Z3_mk_fpa_to_fp_signed(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
10940
10941
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 10242 of file z3py.py.

10242def FPSort(ebits, sbits, ctx=None):
10243 """Return a Z3 floating-point sort of the given sizes. If `ctx=None`, then the global context is used.
10244
10245 >>> Single = FPSort(8, 24)
10246 >>> Double = FPSort(11, 53)
10247 >>> Single
10248 FPSort(8, 24)
10249 >>> x = Const('x', Single)
10250 >>> eq(x, FP('x', FPSort(8, 24)))
10251 True
10252 """
10253 ctx = _get_ctx(ctx)
10254 return FPSortRef(Z3_mk_fpa_sort(ctx.ref(), ebits, sbits), ctx)
10255
10256
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 10659 of file z3py.py.

10659def fpSqrt(rm, a, ctx=None):
10660 """Create a Z3 floating-point square root expression.
10661 """
10662 return _mk_fp_unary(Z3_mk_fpa_sqrt, rm, a, ctx)
10663
10664

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

10564def fpSub(rm, a, b, ctx=None):
10565 """Create a Z3 floating-point subtraction expression.
10566
10567 >>> s = FPSort(8, 24)
10568 >>> rm = RNE()
10569 >>> x = FP('x', s)
10570 >>> y = FP('y', s)
10571 >>> fpSub(rm, x, y)
10572 x - y
10573 >>> fpSub(rm, x, y).sort()
10574 FPSort(8, 24)
10575 """
10576 return _mk_fp_bin(Z3_mk_fpa_sub, rm, a, b, ctx)
10577
10578

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

10830def fpToFP(a1, a2=None, a3=None, ctx=None):
10831 """Create a Z3 floating-point conversion expression from other term sorts
10832 to floating-point.
10833
10834 From a bit-vector term in IEEE 754-2008 format:
10835 >>> x = FPVal(1.0, Float32())
10836 >>> x_bv = fpToIEEEBV(x)
10837 >>> simplify(fpToFP(x_bv, Float32()))
10838 1
10839
10840 From a floating-point term with different precision:
10841 >>> x = FPVal(1.0, Float32())
10842 >>> x_db = fpToFP(RNE(), x, Float64())
10843 >>> x_db.sort()
10844 FPSort(11, 53)
10845
10846 From a real term:
10847 >>> x_r = RealVal(1.5)
10848 >>> simplify(fpToFP(RNE(), x_r, Float32()))
10849 1.5
10850
10851 From a signed bit-vector term:
10852 >>> x_signed = BitVecVal(-5, BitVecSort(32))
10853 >>> simplify(fpToFP(RNE(), x_signed, Float32()))
10854 -1.25*(2**2)
10855 """
10856 ctx = _get_ctx(ctx)
10857 if is_bv(a1) and is_fp_sort(a2):
10858 return FPRef(Z3_mk_fpa_to_fp_bv(ctx.ref(), a1.ast, a2.ast), ctx)
10859 elif is_fprm(a1) and is_fp(a2) and is_fp_sort(a3):
10860 return FPRef(Z3_mk_fpa_to_fp_float(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
10861 elif is_fprm(a1) and is_real(a2) and is_fp_sort(a3):
10862 return FPRef(Z3_mk_fpa_to_fp_real(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
10863 elif is_fprm(a1) and is_bv(a2) and is_fp_sort(a3):
10864 return FPRef(Z3_mk_fpa_to_fp_signed(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
10865 else:
10866 raise Z3Exception("Unsupported combination of arguments for conversion to floating-point term.")
10867
10868

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

10960def fpToFPUnsigned(rm, x, s, ctx=None):
10961 """Create a Z3 floating-point conversion expression, from unsigned bit-vector to floating-point expression."""
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_bv(x), "Second argument must be a Z3 bit-vector expression")
10965 _z3_assert(is_fp_sort(s), "Third argument must be Z3 floating-point sort")
10966 ctx = _get_ctx(ctx)
10967 return FPRef(Z3_mk_fpa_to_fp_unsigned(ctx.ref(), rm.ast, x.ast, s.ast), ctx)
10968
10969
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 11034 of file z3py.py.

11034def fpToIEEEBV(x, ctx=None):
11035 """\brief Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.
11036
11037 The size of the resulting bit-vector is automatically determined.
11038
11039 Note that IEEE 754-2008 allows multiple different representations of NaN. This conversion
11040 knows only one NaN and it will always produce the same bit-vector representation of
11041 that NaN.
11042
11043 >>> x = FP('x', FPSort(8, 24))
11044 >>> y = fpToIEEEBV(x)
11045 >>> print(is_fp(x))
11046 True
11047 >>> print(is_bv(y))
11048 True
11049 >>> print(is_fp(y))
11050 False
11051 >>> print(is_bv(x))
11052 False
11053 """
11054 if z3_debug():
11055 _z3_assert(is_fp(x), "First argument must be a Z3 floating-point expression")
11056 ctx = _get_ctx(ctx)
11057 return BitVecRef(Z3_mk_fpa_to_ieee_bv(ctx.ref(), x.ast), ctx)
11058
11059
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 11014 of file z3py.py.

11014def fpToReal(x, ctx=None):
11015 """Create a Z3 floating-point conversion expression, from floating-point expression to real.
11016
11017 >>> x = FP('x', FPSort(8, 24))
11018 >>> y = fpToReal(x)
11019 >>> print(is_fp(x))
11020 True
11021 >>> print(is_real(y))
11022 True
11023 >>> print(is_fp(y))
11024 False
11025 >>> print(is_real(x))
11026 False
11027 """
11028 if z3_debug():
11029 _z3_assert(is_fp(x), "First argument must be a Z3 floating-point expression")
11030 ctx = _get_ctx(ctx)
11031 return ArithRef(Z3_mk_fpa_to_real(ctx.ref(), x.ast), ctx)
11032
11033
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 10970 of file z3py.py.

10970def fpToSBV(rm, x, s, ctx=None):
10971 """Create a Z3 floating-point conversion expression, from floating-point expression to signed bit-vector.
10972
10973 >>> x = FP('x', FPSort(8, 24))
10974 >>> y = fpToSBV(RTZ(), x, BitVecSort(32))
10975 >>> print(is_fp(x))
10976 True
10977 >>> print(is_bv(y))
10978 True
10979 >>> print(is_fp(y))
10980 False
10981 >>> print(is_bv(x))
10982 False
10983 """
10984 if z3_debug():
10985 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
10986 _z3_assert(is_fp(x), "Second argument must be a Z3 floating-point expression")
10987 _z3_assert(is_bv_sort(s), "Third argument must be Z3 bit-vector sort")
10988 ctx = _get_ctx(ctx)
10989 return BitVecRef(Z3_mk_fpa_to_sbv(ctx.ref(), rm.ast, x.ast, s.size()), ctx)
10990
10991
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 10992 of file z3py.py.

10992def fpToUBV(rm, x, s, ctx=None):
10993 """Create a Z3 floating-point conversion expression, from floating-point expression to unsigned bit-vector.
10994
10995 >>> x = FP('x', FPSort(8, 24))
10996 >>> y = fpToUBV(RTZ(), x, BitVecSort(32))
10997 >>> print(is_fp(x))
10998 True
10999 >>> print(is_bv(y))
11000 True
11001 >>> print(is_fp(y))
11002 False
11003 >>> print(is_bv(x))
11004 False
11005 """
11006 if z3_debug():
11007 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
11008 _z3_assert(is_fp(x), "Second argument must be a Z3 floating-point expression")
11009 _z3_assert(is_bv_sort(s), "Third argument must be Z3 bit-vector sort")
11010 ctx = _get_ctx(ctx)
11011 return BitVecRef(Z3_mk_fpa_to_ubv(ctx.ref(), rm.ast, x.ast, s.size()), ctx)
11012
11013
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 10942 of file z3py.py.

10942def fpUnsignedToFP(rm, v, sort, ctx=None):
10943 """Create a Z3 floating-point conversion expression that represents the
10944 conversion from an unsigned bit-vector term (encoding an integer) to a floating-point term.
10945
10946 >>> x_signed = BitVecVal(-5, BitVecSort(32))
10947 >>> x_fp = fpUnsignedToFP(RNE(), x_signed, Float32())
10948 >>> x_fp
10949 fpToFPUnsigned(RNE(), 4294967291)
10950 >>> simplify(x_fp)
10951 1*(2**32)
10952 """
10953 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10954 _z3_assert(is_bv(v), "Second argument must be a Z3 bit-vector expression")
10955 _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
10956 ctx = _get_ctx(ctx)
10957 return FPRef(Z3_mk_fpa_to_fp_unsigned(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
10958
10959

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

10367def FPVal(sig, exp=None, fps=None, ctx=None):
10368 """Return a floating-point value of value `val` and sort `fps`.
10369 If `ctx=None`, then the global context is used.
10370
10371 >>> v = FPVal(20.0, FPSort(8, 24))
10372 >>> v
10373 1.25*(2**4)
10374 >>> print("0x%.8x" % v.exponent_as_long(False))
10375 0x00000004
10376 >>> v = FPVal(2.25, FPSort(8, 24))
10377 >>> v
10378 1.125*(2**1)
10379 >>> v = FPVal(-2.25, FPSort(8, 24))
10380 >>> v
10381 -1.125*(2**1)
10382 >>> FPVal(-0.0, FPSort(8, 24))
10383 -0.0
10384 >>> FPVal(0.0, FPSort(8, 24))
10385 +0.0
10386 >>> FPVal(+0.0, FPSort(8, 24))
10387 +0.0
10388 """
10389 ctx = _get_ctx(ctx)
10390 if is_fp_sort(exp):
10391 fps = exp
10392 exp = None
10393 elif fps is None:
10394 fps = _dflt_fps(ctx)
10395 _z3_assert(is_fp_sort(fps), "sort mismatch")
10396 if exp is None:
10397 exp = 0
10398 val = _to_float_str(sig)
10399 if val == "NaN" or val == "nan":
10400 return fpNaN(fps)
10401 elif val == "-0.0":
10402 return fpMinusZero(fps)
10403 elif val == "0.0" or val == "+0.0":
10404 return fpPlusZero(fps)
10405 elif val == "+oo" or val == "+inf" or val == "+Inf":
10406 return fpPlusInfinity(fps)
10407 elif val == "-oo" or val == "-inf" or val == "-Inf":
10408 return fpMinusInfinity(fps)
10409 else:
10410 return FPNumRef(Z3_mk_numeral(ctx.ref(), val, fps.ast), ctx)
10411
10412

◆ fpZero()

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

Definition at line 10360 of file z3py.py.

10360def fpZero(s, negative):
10361 """Create a Z3 floating-point +0.0 or -0.0 term."""
10362 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10363 _z3_assert(isinstance(negative, bool), "expected Boolean flag")
10364 return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, negative), s.ctx)
10365
10366

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

1907def FreshBool(prefix="b", ctx=None):
1908 """Return a fresh Boolean constant in the given context using the given prefix.
1909
1910 If `ctx=None`, then the global context is used.
1911
1912 >>> b1 = FreshBool()
1913 >>> b2 = FreshBool()
1914 >>> eq(b1, b2)
1915 False
1916 """
1917 ctx = _get_ctx(ctx)
1918 return BoolRef(Z3_mk_fresh_const(ctx.ref(), prefix, BoolSort(ctx).ast), ctx)
1919
1920
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 1570 of file z3py.py.

1570def FreshConst(sort, prefix="c"):
1571 """Create a fresh constant of a specified sort"""
1572 if z3_debug():
1573 _z3_assert(is_sort(sort), f"Z3 sort expected, got {type(sort)}")
1574 ctx = _get_ctx(sort.ctx)
1575 return _to_expr_ref(Z3_mk_fresh_const(ctx.ref(), prefix, sort.ast), ctx)
1576
1577

◆ FreshFunction()

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

Definition at line 946 of file z3py.py.

946def FreshFunction(*sig):
947 """Create a new fresh Z3 uninterpreted function with the given sorts.
948 """
949 sig = _get_args(sig)
950 if z3_debug():
951 _z3_assert(len(sig) > 0, "At least two arguments expected")
952 arity = len(sig) - 1
953 rng = sig[arity]
954 if z3_debug():
955 _z3_assert(is_sort(rng), "Z3 sort expected")
956 dom = (z3.Sort * arity)()
957 for i in range(arity):
958 if z3_debug():
959 _z3_assert(is_sort(sig[i]), "Z3 sort expected")
960 dom[i] = sig[i].ast
961 ctx = rng.ctx
962 return FuncDeclRef(Z3_mk_fresh_func_decl(ctx.ref(), "f", arity, dom, rng.ast), ctx)
963
964
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 3435 of file z3py.py.

3435def FreshInt(prefix="x", ctx=None):
3436 """Return a fresh integer constant in the given context using the given prefix.
3437
3438 >>> x = FreshInt()
3439 >>> y = FreshInt()
3440 >>> eq(x, y)
3441 False
3442 >>> x.sort()
3443 Int
3444 """
3445 ctx = _get_ctx(ctx)
3446 return ArithRef(Z3_mk_fresh_const(ctx.ref(), prefix, IntSort(ctx).ast), ctx)
3447
3448

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

3492def FreshReal(prefix="b", ctx=None):
3493 """Return a fresh real constant in the given context using the given prefix.
3494
3495 >>> x = FreshReal()
3496 >>> y = FreshReal()
3497 >>> eq(x, y)
3498 False
3499 >>> x.sort()
3500 Real
3501 """
3502 ctx = _get_ctx(ctx)
3503 return ArithRef(Z3_mk_fresh_const(ctx.ref(), prefix, RealSort(ctx).ast), ctx)
3504
3505

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

11337def Full(s):
11338 """Create the regular expression that accepts the universal language
11339 >>> e = Full(ReSort(SeqSort(IntSort())))
11340 >>> print(e)
11341 Full(ReSort(Seq(Int)))
11342 >>> e1 = Full(ReSort(StringSort()))
11343 >>> print(e1)
11344 Full(ReSort(String))
11345 """
11346 if isinstance(s, ReSortRef):
11347 return ReRef(Z3_mk_re_full(s.ctx_ref(), s.ast), s.ctx)
11348 raise Z3Exception("Non-sequence, non-regular expression sort passed to Full")
11349
11350
11351
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 5102 of file z3py.py.

5102def FullSet(s):
5103 """Create the full set
5104 >>> FullSet(IntSort())
5105 K(Int, True)
5106 """
5107 ctx = s.ctx
5108 return ArrayRef(Z3_mk_full_set(ctx.ref(), s.ast), ctx)
5109
5110
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 923 of file z3py.py.

923def Function(name, *sig):
924 """Create a new Z3 uninterpreted function with the given sorts.
925
926 >>> f = Function('f', IntSort(), IntSort())
927 >>> f(f(0))
928 f(f(0))
929 """
930 sig = _get_args(sig)
931 if z3_debug():
932 _z3_assert(len(sig) > 0, "At least two arguments expected")
933 arity = len(sig) - 1
934 rng = sig[arity]
935 if z3_debug():
936 _z3_assert(is_sort(rng), "Z3 sort expected")
937 dom = (Sort * arity)()
938 for i in range(arity):
939 if z3_debug():
940 _z3_assert(is_sort(sig[i]), "Z3 sort expected")
941 dom[i] = sig[i].ast
942 ctx = rng.ctx
943 return FuncDeclRef(Z3_mk_func_decl(ctx.ref(), to_symbol(name, ctx), arity, dom, rng.ast), ctx)
944
945
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 6917 of file z3py.py.

6917def get_as_array_func(n):
6918 """Return the function declaration f associated with a Z3 expression of the form (_ as-array f)."""
6919 if z3_debug():
6920 _z3_assert(is_as_array(n), "as-array Z3 expression expected.")
6921 return FuncDeclRef(Z3_get_as_array_func_decl(n.ctx.ref(), n.as_ast()), n.ctx)
6922
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 297 of file z3py.py.

297def get_ctx(ctx) -> Context:
298 return _get_ctx(ctx)
299
300

◆ get_default_fp_sort()

get_default_fp_sort (   ctx = None)

Definition at line 9654 of file z3py.py.

9654def get_default_fp_sort(ctx=None):
9655 return FPSort(_dflt_fpsort_ebits, _dflt_fpsort_sbits, ctx)
9656
9657

◆ get_default_rounding_mode()

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

Definition at line 9621 of file z3py.py.

9621def get_default_rounding_mode(ctx=None):
9622 """Retrieves the global default rounding mode."""
9623 global _dflt_rounding_mode
9624 if _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO:
9625 return RTZ(ctx)
9626 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE:
9627 return RTN(ctx)
9628 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE:
9629 return RTP(ctx)
9630 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN:
9631 return RNE(ctx)
9632 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY:
9633 return RNA(ctx)
9634
9635

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

4854def get_map_func(a):
4855 """Return the function declaration associated with a Z3 map array expression.
4856
4857 >>> f = Function('f', IntSort(), IntSort())
4858 >>> b = Array('b', IntSort(), IntSort())
4859 >>> a = Map(f, b)
4860 >>> eq(f, get_map_func(a))
4861 True
4862 >>> get_map_func(a)
4863 f
4864 >>> get_map_func(a)(0)
4865 f(0)
4866 """
4867 if z3_debug():
4868 _z3_assert(is_map(a), "Z3 array map expression expected.")
4869 return FuncDeclRef(
4871 a.ctx_ref(),
4872 Z3_get_decl_ast_parameter(a.ctx_ref(), a.decl().ast, 0),
4873 ),
4874 ctx=a.ctx,
4875 )
4876
4877
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 337 of file z3py.py.

337def get_param(name):
338 """Return the value of a Z3 global (or module) parameter
339
340 >>> get_param('nlsat.reorder')
341 'true'
342 """
343 ptr = (ctypes.c_char_p * 1)()
344 if Z3_global_param_get(str(name), ptr):
345 r = z3core._to_pystr(ptr[0])
346 return r
347 raise Z3Exception("failed to retrieve value for '%s'" % name)
348
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 1441 of file z3py.py.

1441def get_var_index(a):
1442 """Return the de-Bruijn index of the Z3 bounded variable `a`.
1443
1444 >>> x = Int('x')
1445 >>> y = Int('y')
1446 >>> is_var(x)
1447 False
1448 >>> is_const(x)
1449 True
1450 >>> f = Function('f', IntSort(), IntSort(), IntSort())
1451 >>> # Z3 replaces x and y with bound variables when ForAll is executed.
1452 >>> q = ForAll([x, y], f(x, y) == x + y)
1453 >>> q.body()
1454 f(Var(1), Var(0)) == Var(1) + Var(0)
1455 >>> b = q.body()
1456 >>> b.arg(0)
1457 f(Var(1), Var(0))
1458 >>> v1 = b.arg(0).arg(0)
1459 >>> v2 = b.arg(0).arg(1)
1460 >>> v1
1461 Var(1)
1462 >>> v2
1463 Var(0)
1464 >>> get_var_index(v1)
1465 1
1466 >>> get_var_index(v2)
1467 0
1468 """
1469 if z3_debug():
1470 _z3_assert(is_var(a), "Z3 bound variable expected")
1471 return int(Z3_get_index_value(a.ctx.ref(), a.as_ast()))
1472
1473
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 9127 of file z3py.py.

9127def help_simplify():
9128 """Return a string describing all options available for Z3 `simplify` procedure."""
9129 print(Z3_simplify_get_help(main_ctx().ref()))
9130
9131
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 1487 of file z3py.py.

1487def If(a, b, c, ctx=None):
1488 """Create a Z3 if-then-else expression.
1489
1490 >>> x = Int('x')
1491 >>> y = Int('y')
1492 >>> max = If(x > y, x, y)
1493 >>> max
1494 If(x > y, x, y)
1495 >>> simplify(max)
1496 If(x <= y, y, x)
1497 """
1498 if isinstance(a, Probe) or isinstance(b, Tactic) or isinstance(c, Tactic):
1499 return Cond(a, b, c, ctx)
1500 else:
1501 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b, c], ctx))
1502 s = BoolSort(ctx)
1503 a = s.cast(a)
1504 b, c = _coerce_exprs(b, c, ctx)
1505 if z3_debug():
1506 _z3_assert(a.ctx == b.ctx, "Context mismatch")
1507 return _to_expr_ref(Z3_mk_ite(ctx.ref(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
1508
1509
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 1921 of file z3py.py.

1921def Implies(a, b, ctx=None):
1922 """Create a Z3 implies expression.
1923
1924 >>> p, q = Bools('p q')
1925 >>> Implies(p, q)
1926 Implies(p, q)
1927 """
1928 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1929 s = BoolSort(ctx)
1930 a = s.cast(a)
1931 b = s.cast(b)
1932 return BoolRef(Z3_mk_implies(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
1933
1934
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 11421 of file z3py.py.

11421def IndexOf(s, substr, offset=None):
11422 """Retrieve the index of substring within a string starting at a specified offset.
11423 >>> simplify(IndexOf("abcabc", "bc", 0))
11424 1
11425 >>> simplify(IndexOf("abcabc", "bc", 2))
11426 4
11427 """
11428 if offset is None:
11429 offset = IntVal(0)
11430 ctx = None
11431 if is_expr(offset):
11432 ctx = offset.ctx
11433 ctx = _get_ctx2(s, substr, ctx)
11434 s = _coerce_seq(s, ctx)
11435 substr = _coerce_seq(substr, ctx)
11436 if _is_int(offset):
11437 offset = IntVal(offset, ctx)
11438 return ArithRef(Z3_mk_seq_index(s.ctx_ref(), s.as_ast(), substr.as_ast(), offset.as_ast()), s.ctx)
11439
11440
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 11560 of file z3py.py.

11560def InRe(s, re):
11561 """Create regular expression membership test
11562 >>> re = Union(Re("a"),Re("b"))
11563 >>> print (simplify(InRe("a", re)))
11564 True
11565 >>> print (simplify(InRe("b", re)))
11566 True
11567 >>> print (simplify(InRe("c", re)))
11568 False
11569 """
11570 s = _coerce_seq(s, re.ctx)
11571 return BoolRef(Z3_mk_seq_in_re(s.ctx_ref(), s.as_ast(), re.as_ast()), s.ctx)
11572
11573
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 3396 of file z3py.py.

3396def Int(name, ctx=None):
3397 """Return an integer constant named `name`. If `ctx=None`, then the global context is used.
3398
3399 >>> x = Int('x')
3400 >>> is_int(x)
3401 True
3402 >>> is_int(x + 1)
3403 True
3404 """
3405 ctx = _get_ctx(ctx)
3406 return ArithRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), IntSort(ctx).ast), ctx)
3407
3408

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

4151def Int2BV(a, num_bits):
4152 """Return the z3 expression Int2BV(a, num_bits).
4153 It is a bit-vector of width num_bits and represents the
4154 modulo of a by 2^num_bits
4155 """
4156 ctx = a.ctx
4157 return BitVecRef(Z3_mk_int2bv(ctx.ref(), num_bits, a.as_ast()), ctx)
4158
4159
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 11594 of file z3py.py.

11594def Intersect(*args):
11595 """Create intersection of regular expressions.
11596 >>> re = Intersect(Re("a"), Re("b"), Re("c"))
11597 """
11598 args = _get_args(args)
11599 sz = len(args)
11600 if z3_debug():
11601 _z3_assert(sz > 0, "At least one argument expected.")
11602 _z3_assert(all([is_re(a) for a in args]), "All arguments must be regular expressions.")
11603 if sz == 1:
11604 return args[0]
11605 ctx = args[0].ctx
11606 v = (Ast * sz)()
11607 for i in range(sz):
11608 v[i] = args[i].as_ast()
11609 return ReRef(Z3_mk_re_intersect(ctx.ref(), sz, v), ctx)
11610
11611
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 3409 of file z3py.py.

3409def Ints(names, ctx=None):
3410 """Return a tuple of Integer constants.
3411
3412 >>> x, y, z = Ints('x y z')
3413 >>> Sum(x, y, z)
3414 x + y + z
3415 """
3416 ctx = _get_ctx(ctx)
3417 if isinstance(names, str):
3418 names = names.split(" ")
3419 return [Int(name, ctx) for name in names]
3420
3421

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

3290def IntSort(ctx=None):
3291 """Return the integer sort in the given context. If `ctx=None`, then the global context is used.
3292
3293 >>> IntSort()
3294 Int
3295 >>> x = Const('x', IntSort())
3296 >>> is_int(x)
3297 True
3298 >>> x.sort() == IntSort()
3299 True
3300 >>> x.sort() == BoolSort()
3301 False
3302 """
3303 ctx = _get_ctx(ctx)
3304 return ArithSortRef(Z3_mk_int_sort(ctx.ref()), ctx)
3305
3306
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 11502 of file z3py.py.

11502def IntToStr(s):
11503 """Convert integer expression to string"""
11504 if not is_expr(s):
11505 s = _py2expr(s)
11506 return SeqRef(Z3_mk_int_to_str(s.ctx_ref(), s.as_ast()), s.ctx)
11507
11508
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 3336 of file z3py.py.

3336def IntVal(val, ctx=None):
3337 """Return a Z3 integer value. If `ctx=None`, then the global context is used.
3338
3339 >>> IntVal(1)
3340 1
3341 >>> IntVal("100")
3342 100
3343 """
3344 ctx = _get_ctx(ctx)
3345 return IntNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), IntSort(ctx).ast), ctx)
3346
3347

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

3422def IntVector(prefix, sz, ctx=None):
3423 """Return a list of integer constants of size `sz`.
3424
3425 >>> X = IntVector('x', 3)
3426 >>> X
3427 [x__0, x__1, x__2]
3428 >>> Sum(X)
3429 x__0 + x__1 + x__2
3430 """
3431 ctx = _get_ctx(ctx)
3432 return [Int("%s__%s" % (prefix, i), ctx) for i in range(sz)]
3433
3434

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

2938def is_add(a : Any) -> bool:
2939 """Return `True` if `a` is an expression of the form b + c.
2940
2941 >>> x, y = Ints('x y')
2942 >>> is_add(x + y)
2943 True
2944 >>> is_add(x - y)
2945 False
2946 """
2947 return is_app_of(a, Z3_OP_ADD)
2948
2949

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

2924def is_algebraic_value(a):
2925 """Return `True` if `a` is an algebraic value of sort Real.
2926
2927 >>> is_algebraic_value(RealVal("3/5"))
2928 False
2929 >>> n = simplify(Sqrt(2))
2930 >>> n
2931 1.4142135623?
2932 >>> is_algebraic_value(n)
2933 True
2934 """
2935 return is_arith(a) and a.is_real() and _is_algebraic(a.ctx, a.as_ast())
2936
2937

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

1757def is_and(a : Any) -> bool:
1758 """Return `True` if `a` is a Z3 and expression.
1759
1760 >>> p, q = Bools('p q')
1761 >>> is_and(And(p, q))
1762 True
1763 >>> is_and(Or(p, q))
1764 False
1765 """
1766 return is_app_of(a, Z3_OP_AND)
1767
1768

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

1371def is_app(a):
1372 """Return `True` if `a` is a Z3 function application.
1373
1374 Note that, constants are function applications with 0 arguments.
1375
1376 >>> a = Int('a')
1377 >>> is_app(a)
1378 True
1379 >>> is_app(a + 1)
1380 True
1381 >>> is_app(IntSort())
1382 False
1383 >>> is_app(1)
1384 False
1385 >>> is_app(IntVal(1))
1386 True
1387 >>> x = Int('x')
1388 >>> is_app(ForAll(x, x >= 0))
1389 False
1390 """
1391 if not isinstance(a, ExprRef):
1392 return False
1393 k = _ast_kind(a.ctx, a)
1394 return k == Z3_NUMERAL_AST or k == Z3_APP_AST
1395
1396

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

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

1474def is_app_of(a, k):
1475 """Return `True` if `a` is an application of the given kind `k`.
1476
1477 >>> x = Int('x')
1478 >>> n = x + 1
1479 >>> is_app_of(n, Z3_OP_ADD)
1480 True
1481 >>> is_app_of(n, Z3_OP_MUL)
1482 False
1483 """
1484 return is_app(a) and a.kind() == k
1485
1486

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

2811def is_arith(a):
2812 """Return `True` if `a` is an arithmetical expression.
2813
2814 >>> x = Int('x')
2815 >>> is_arith(x)
2816 True
2817 >>> is_arith(x + 1)
2818 True
2819 >>> is_arith(1)
2820 False
2821 >>> is_arith(IntVal(1))
2822 True
2823 >>> y = Real('y')
2824 >>> is_arith(y)
2825 True
2826 >>> is_arith(y + 1)
2827 True
2828 """
2829 return isinstance(a, ArithRef)
2830
2831

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

2510def is_arith_sort(s : Any) -> bool:
2511 """Return `True` if s is an arithmetical sort (type).
2512
2513 >>> is_arith_sort(IntSort())
2514 True
2515 >>> is_arith_sort(RealSort())
2516 True
2517 >>> is_arith_sort(BoolSort())
2518 False
2519 >>> n = Int('x') + 1
2520 >>> is_arith_sort(n.sort())
2521 True
2522 """
2523 return isinstance(s, ArithSortRef)
2524
2525

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

4789def is_array(a : Any) -> bool:
4790 """Return `True` if `a` is a Z3 array expression.
4791
4792 >>> a = Array('a', IntSort(), IntSort())
4793 >>> is_array(a)
4794 True
4795 >>> is_array(Store(a, 0, 1))
4796 True
4797 >>> is_array(a[0])
4798 False
4799 """
4800 return isinstance(a, ArrayRef)
4801
4802

Referenced by Ext(), and Map().

◆ is_array_sort()

is_array_sort (   a)

Definition at line 4785 of file z3py.py.

4785def is_array_sort(a):
4786 return Z3_get_sort_kind(a.ctx.ref(), Z3_get_sort(a.ctx.ref(), a.ast)) == Z3_ARRAY_SORT
4787
4788

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

6912def is_as_array(n):
6913 """Return true if n is a Z3 expression of the form (_ as-array f)."""
6914 return isinstance(n, ExprRef) and Z3_is_as_array(n.ctx.ref(), n.as_ast())
6915
6916
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 485 of file z3py.py.

485def is_ast(a : Any) -> bool:
486 """Return `True` if `a` is an AST node.
487
488 >>> is_ast(10)
489 False
490 >>> is_ast(IntVal(10))
491 True
492 >>> is_ast(Int('x'))
493 True
494 >>> is_ast(BoolSort())
495 True
496 >>> is_ast(Function('f', IntSort(), IntSort()))
497 True
498 >>> is_ast("x")
499 False
500 >>> is_ast(Solver())
501 False
502 """
503 return isinstance(a, AstRef)
504
505

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

1707def is_bool(a : Any) -> bool:
1708 """Return `True` if `a` is a Z3 Boolean expression.
1709
1710 >>> p = Bool('p')
1711 >>> is_bool(p)
1712 True
1713 >>> q = Bool('q')
1714 >>> is_bool(And(p, q))
1715 True
1716 >>> x = Real('x')
1717 >>> is_bool(x)
1718 False
1719 >>> is_bool(x == 0)
1720 True
1721 """
1722 return isinstance(a, BoolRef)
1723
1724

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

4099def is_bv(a):
4100 """Return `True` if `a` is a Z3 bit-vector expression.
4101
4102 >>> b = BitVec('b', 32)
4103 >>> is_bv(b)
4104 True
4105 >>> is_bv(b + 10)
4106 True
4107 >>> is_bv(Int('x'))
4108 False
4109 """
4110 return isinstance(a, BitVecRef)
4111
4112

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

3626def is_bv_sort(s):
3627 """Return True if `s` is a Z3 bit-vector sort.
3628
3629 >>> is_bv_sort(BitVecSort(32))
3630 True
3631 >>> is_bv_sort(IntSort())
3632 False
3633 """
3634 return isinstance(s, BitVecSortRef)
3635
3636

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

4113def is_bv_value(a):
4114 """Return `True` if `a` is a Z3 bit-vector numeral value.
4115
4116 >>> b = BitVec('b', 32)
4117 >>> is_bv_value(b)
4118 False
4119 >>> b = BitVecVal(10, 32)
4120 >>> b
4121 10
4122 >>> is_bv_value(b)
4123 True
4124 """
4125 return is_bv(a) and _is_numeral(a.ctx, a.as_ast())
4126
4127

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

1397def is_const(a):
1398 """Return `True` if `a` is Z3 constant/variable expression.
1399
1400 >>> a = Int('a')
1401 >>> is_const(a)
1402 True
1403 >>> is_const(a + 1)
1404 False
1405 >>> is_const(1)
1406 False
1407 >>> is_const(IntVal(1))
1408 True
1409 >>> x = Int('x')
1410 >>> is_const(ForAll(x, x >= 0))
1411 False
1412 """
1413 return is_app(a) and a.num_args() == 0
1414
1415

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

4803def is_const_array(a):
4804 """Return `True` if `a` is a Z3 constant array.
4805
4806 >>> a = K(IntSort(), 10)
4807 >>> is_const_array(a)
4808 True
4809 >>> a = Array('a', IntSort(), IntSort())
4810 >>> is_const_array(a)
4811 False
4812 """
4813 return is_app_of(a, Z3_OP_CONST_ARRAY)
4814
4815

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

4845def is_default(a):
4846 """Return `True` if `a` is a Z3 default array expression.
4847 >>> d = Default(K(IntSort(), 10))
4848 >>> is_default(d)
4849 True
4850 """
4851 return is_app_of(a, Z3_OP_ARRAY_DEFAULT)
4852
4853

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

1815def is_distinct(a : Any) -> bool:
1816 """Return `True` if `a` is a Z3 distinct expression.
1817
1818 >>> x, y, z = Ints('x y z')
1819 >>> is_distinct(x == y)
1820 False
1821 >>> is_distinct(Distinct(x, y, z))
1822 True
1823 """
1824 return is_app_of(a, Z3_OP_DISTINCT)
1825
1826

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

2974def is_div(a : Any) -> bool:
2975 """Return `True` if `a` is an expression of the form b / c.
2976
2977 >>> x, y = Reals('x y')
2978 >>> is_div(x / y)
2979 True
2980 >>> is_div(x + y)
2981 False
2982 >>> x, y = Ints('x y')
2983 >>> is_div(x / y)
2984 False
2985 >>> is_idiv(x / y)
2986 True
2987 """
2988 return is_app_of(a, Z3_OP_DIV)
2989
2990

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

1805def is_eq(a : Any) -> bool:
1806 """Return `True` if `a` is a Z3 equality expression.
1807
1808 >>> x, y = Ints('x y')
1809 >>> is_eq(x == y)
1810 True
1811 """
1812 return is_app_of(a, Z3_OP_EQ)
1813
1814

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

1348def is_expr(a):
1349 """Return `True` if `a` is a Z3 expression.
1350
1351 >>> a = Int('a')
1352 >>> is_expr(a)
1353 True
1354 >>> is_expr(a + 1)
1355 True
1356 >>> is_expr(IntSort())
1357 False
1358 >>> is_expr(1)
1359 False
1360 >>> is_expr(IntVal(1))
1361 True
1362 >>> x = Int('x')
1363 >>> is_expr(ForAll(x, x >= 0))
1364 True
1365 >>> is_expr(FPVal(1.0))
1366 True
1367 """
1368 return isinstance(a, ExprRef)
1369
1370

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(), ExprRef.update(), 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 1743 of file z3py.py.

1743def is_false(a : Any) -> bool:
1744 """Return `True` if `a` is the Z3 false expression.
1745
1746 >>> p = Bool('p')
1747 >>> is_false(p)
1748 False
1749 >>> is_false(False)
1750 False
1751 >>> is_false(BoolVal(False))
1752 True
1753 """
1754 return is_app_of(a, Z3_OP_FALSE)
1755
1756

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

8005def is_finite_domain(a):
8006 """Return `True` if `a` is a Z3 finite-domain expression.
8007
8008 >>> s = FiniteDomainSort('S', 100)
8009 >>> b = Const('b', s)
8010 >>> is_finite_domain(b)
8011 True
8012 >>> is_finite_domain(Int('x'))
8013 False
8014 """
8015 return isinstance(a, FiniteDomainRef)
8016
8017

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

7982def is_finite_domain_sort(s):
7983 """Return True if `s` is a Z3 finite-domain sort.
7984
7985 >>> is_finite_domain_sort(FiniteDomainSort('S', 100))
7986 True
7987 >>> is_finite_domain_sort(IntSort())
7988 False
7989 """
7990 return isinstance(s, FiniteDomainSortRef)
7991
7992

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

8059def is_finite_domain_value(a):
8060 """Return `True` if `a` is a Z3 finite-domain value.
8061
8062 >>> s = FiniteDomainSort('S', 100)
8063 >>> b = Const('b', s)
8064 >>> is_finite_domain_value(b)
8065 False
8066 >>> b = FiniteDomainVal(10, s)
8067 >>> b
8068 10
8069 >>> is_finite_domain_value(b)
8070 True
8071 """
8072 return is_finite_domain(a) and _is_numeral(a.ctx, a.as_ast())
8073
8074

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

10213def is_fp(a):
10214 """Return `True` if `a` is a Z3 floating-point expression.
10215
10216 >>> b = FP('b', FPSort(8, 24))
10217 >>> is_fp(b)
10218 True
10219 >>> is_fp(b + 1.0)
10220 True
10221 >>> is_fp(Int('x'))
10222 False
10223 """
10224 return isinstance(a, FPRef)
10225
10226

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

9787def is_fp_sort(s):
9788 """Return True if `s` is a Z3 floating-point sort.
9789
9790 >>> is_fp_sort(FPSort(8, 24))
9791 True
9792 >>> is_fp_sort(IntSort())
9793 False
9794 """
9795 return isinstance(s, FPSortRef)
9796
9797

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

10227def is_fp_value(a):
10228 """Return `True` if `a` is a Z3 floating-point numeral value.
10229
10230 >>> b = FP('b', FPSort(8, 24))
10231 >>> is_fp_value(b)
10232 False
10233 >>> b = FPVal(1.0, FPSort(8, 24))
10234 >>> b
10235 1
10236 >>> is_fp_value(b)
10237 True
10238 """
10239 return is_fp(a) and _is_numeral(a.ctx, a.ast)
10240
10241

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

10047def is_fprm(a):
10048 """Return `True` if `a` is a Z3 floating-point rounding mode expression.
10049
10050 >>> rm = RNE()
10051 >>> is_fprm(rm)
10052 True
10053 >>> rm = 1.0
10054 >>> is_fprm(rm)
10055 False
10056 """
10057 return isinstance(a, FPRMRef)
10058
10059

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

9798def is_fprm_sort(s):
9799 """Return True if `s` is a Z3 floating-point rounding mode sort.
9800
9801 >>> is_fprm_sort(FPSort(8, 24))
9802 False
9803 >>> is_fprm_sort(RNE().sort())
9804 True
9805 """
9806 return isinstance(s, FPRMSortRef)
9807
9808# FP Expressions
9809
9810

◆ is_fprm_value()

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

Definition at line 10060 of file z3py.py.

10060def is_fprm_value(a):
10061 """Return `True` if `a` is a Z3 floating-point rounding mode numeral value."""
10062 return is_fprm(a) and _is_numeral(a.ctx, a.ast)
10063
10064# FP Numerals
10065
10066

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

910def is_func_decl(a):
911 """Return `True` if `a` is a Z3 function declaration.
912
913 >>> f = Function('f', IntSort(), IntSort())
914 >>> is_func_decl(f)
915 True
916 >>> x = Real('x')
917 >>> is_func_decl(x)
918 False
919 """
920 return isinstance(a, FuncDeclRef)
921
922

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

3039def is_ge(a : Any) -> bool:
3040 """Return `True` if `a` is an expression of the form b >= c.
3041
3042 >>> x, y = Ints('x y')
3043 >>> is_ge(x >= y)
3044 True
3045 >>> is_ge(x == y)
3046 False
3047 """
3048 return is_app_of(a, Z3_OP_GE)
3049
3050

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

3051def is_gt(a : Any) -> bool:
3052 """Return `True` if `a` is an expression of the form b > c.
3053
3054 >>> x, y = Ints('x y')
3055 >>> is_gt(x > y)
3056 True
3057 >>> is_gt(x == y)
3058 False
3059 """
3060 return is_app_of(a, Z3_OP_GT)
3061
3062

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

2991def is_idiv(a : Any) -> bool:
2992 """Return `True` if `a` is an expression of the form b div c.
2993
2994 >>> x, y = Ints('x y')
2995 >>> is_idiv(x / y)
2996 True
2997 >>> is_idiv(x + y)
2998 False
2999 """
3000 return is_app_of(a, Z3_OP_IDIV)
3001
3002

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

1781def is_implies(a : Any) -> bool:
1782 """Return `True` if `a` is a Z3 implication expression.
1783
1784 >>> p, q = Bools('p q')
1785 >>> is_implies(Implies(p, q))
1786 True
1787 >>> is_implies(And(p, q))
1788 False
1789 """
1790 return is_app_of(a, Z3_OP_IMPLIES)
1791
1792

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

2832def is_int(a) -> bool:
2833 """Return `True` if `a` is an integer expression.
2834
2835 >>> x = Int('x')
2836 >>> is_int(x + 1)
2837 True
2838 >>> is_int(1)
2839 False
2840 >>> is_int(IntVal(1))
2841 True
2842 >>> y = Real('y')
2843 >>> is_int(y)
2844 False
2845 >>> is_int(y + 1)
2846 False
2847 """
2848 return is_arith(a) and a.is_int()
2849
2850

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

2878def is_int_value(a):
2879 """Return `True` if `a` is an integer value of sort Int.
2880
2881 >>> is_int_value(IntVal(1))
2882 True
2883 >>> is_int_value(1)
2884 False
2885 >>> is_int_value(Int('x'))
2886 False
2887 >>> n = Int('x') + 1
2888 >>> n
2889 x + 1
2890 >>> n.arg(1)
2891 1
2892 >>> is_int_value(n.arg(1))
2893 True
2894 >>> is_int_value(RealVal("1/3"))
2895 False
2896 >>> is_int_value(RealVal(1))
2897 False
2898 """
2899 return is_arith(a) and a.is_int() and _is_numeral(a.ctx, a.as_ast())
2900
2901

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

3063def is_is_int(a : Any) -> bool:
3064 """Return `True` if `a` is an expression of the form IsInt(b).
3065
3066 >>> x = Real('x')
3067 >>> is_is_int(IsInt(x))
3068 True
3069 >>> is_is_int(x)
3070 False
3071 """
3072 return is_app_of(a, Z3_OP_IS_INT)
3073
3074

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

4816def is_K(a):
4817 """Return `True` if `a` is a Z3 constant array.
4818
4819 >>> a = K(IntSort(), 10)
4820 >>> is_K(a)
4821 True
4822 >>> a = Array('a', IntSort(), IntSort())
4823 >>> is_K(a)
4824 False
4825 """
4826 return is_app_of(a, Z3_OP_CONST_ARRAY)
4827
4828

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

3015def is_le(a : Any) -> bool:
3016 """Return `True` if `a` is an expression of the form b <= c.
3017
3018 >>> x, y = Ints('x y')
3019 >>> is_le(x <= y)
3020 True
3021 >>> is_le(x < y)
3022 False
3023 """
3024 return is_app_of(a, Z3_OP_LE)
3025
3026

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

3027def is_lt(a : Any) -> bool:
3028 """Return `True` if `a` is an expression of the form b < c.
3029
3030 >>> x, y = Ints('x y')
3031 >>> is_lt(x < y)
3032 True
3033 >>> is_lt(x == y)
3034 False
3035 """
3036 return is_app_of(a, Z3_OP_LT)
3037
3038

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

4829def is_map(a):
4830 """Return `True` if `a` is a Z3 map array expression.
4831
4832 >>> f = Function('f', IntSort(), IntSort())
4833 >>> b = Array('b', IntSort(), IntSort())
4834 >>> a = Map(f, b)
4835 >>> a
4836 Map(f, b)
4837 >>> is_map(a)
4838 True
4839 >>> is_map(b)
4840 False
4841 """
4842 return is_app_of(a, Z3_OP_ARRAY_MAP)
4843
4844

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

3003def is_mod(a : Any) -> bool:
3004 """Return `True` if `a` is an expression of the form b % c.
3005
3006 >>> x, y = Ints('x y')
3007 >>> is_mod(x % y)
3008 True
3009 >>> is_mod(x + y)
3010 False
3011 """
3012 return is_app_of(a, Z3_OP_MOD)
3013
3014

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

2950def is_mul(a : Any) -> bool:
2951 """Return `True` if `a` is an expression of the form b * c.
2952
2953 >>> x, y = Ints('x y')
2954 >>> is_mul(x * y)
2955 True
2956 >>> is_mul(x - y)
2957 False
2958 """
2959 return is_app_of(a, Z3_OP_MUL)
2960
2961

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

1793def is_not(a : Any) -> bool:
1794 """Return `True` if `a` is a Z3 not expression.
1795
1796 >>> p = Bool('p')
1797 >>> is_not(p)
1798 False
1799 >>> is_not(Not(p))
1800 True
1801 """
1802 return is_app_of(a, Z3_OP_NOT)
1803
1804

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

1769def is_or(a : Any) -> bool:
1770 """Return `True` if `a` is a Z3 or expression.
1771
1772 >>> p, q = Bools('p q')
1773 >>> is_or(Or(p, q))
1774 True
1775 >>> is_or(And(p, q))
1776 False
1777 """
1778 return is_app_of(a, Z3_OP_OR)
1779
1780

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

2069def is_pattern(a):
2070 """Return `True` if `a` is a Z3 pattern (hint for quantifier instantiation.
2071
2072 >>> f = Function('f', IntSort(), IntSort())
2073 >>> x = Int('x')
2074 >>> q = ForAll(x, f(x) == 0, patterns = [ f(x) ])
2075 >>> q
2076 ForAll(x, f(x) == 0)
2077 >>> q.num_patterns()
2078 1
2079 >>> is_pattern(q.pattern(0))
2080 True
2081 >>> q.pattern(0)
2082 f(Var(0))
2083 """
2084 return isinstance(a, PatternRef)
2085
2086

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

8968def is_probe(p):
8969 """Return `True` if `p` is a Z3 probe.
8970
8971 >>> is_probe(Int('x'))
8972 False
8973 >>> is_probe(Probe('memory'))
8974 True
8975 """
8976 return isinstance(p, Probe)
8977
8978

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

2319def is_quantifier(a):
2320 """Return `True` if `a` is a Z3 quantifier.
2321
2322 >>> f = Function('f', IntSort(), IntSort())
2323 >>> x = Int('x')
2324 >>> q = ForAll(x, f(x) == 0)
2325 >>> is_quantifier(q)
2326 True
2327 >>> is_quantifier(f(x))
2328 False
2329 """
2330 return isinstance(a, QuantifierRef)
2331
2332

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

2902def is_rational_value(a):
2903 """Return `True` if `a` is rational value of sort Real.
2904
2905 >>> is_rational_value(RealVal(1))
2906 True
2907 >>> is_rational_value(RealVal("3/5"))
2908 True
2909 >>> is_rational_value(IntVal(1))
2910 False
2911 >>> is_rational_value(1)
2912 False
2913 >>> n = Real('x') + 1
2914 >>> n.arg(1)
2915 1
2916 >>> is_rational_value(n.arg(1))
2917 True
2918 >>> is_rational_value(Real('x'))
2919 False
2920 """
2921 return is_arith(a) and a.is_real() and _is_numeral(a.ctx, a.as_ast())
2922
2923

◆ is_re()

is_re (   s)

Definition at line 11556 of file z3py.py.

11556def is_re(s):
11557 return isinstance(s, ReRef)
11558
11559

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

2851def is_real(a):
2852 """Return `True` if `a` is a real expression.
2853
2854 >>> x = Int('x')
2855 >>> is_real(x + 1)
2856 False
2857 >>> y = Real('y')
2858 >>> is_real(y)
2859 True
2860 >>> is_real(y + 1)
2861 True
2862 >>> is_real(1)
2863 False
2864 >>> is_real(RealVal(1))
2865 True
2866 """
2867 return is_arith(a) and a.is_real()
2868
2869

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

5057def is_select(a):
5058 """Return `True` if `a` is a Z3 array select application.
5059
5060 >>> a = Array('a', IntSort(), IntSort())
5061 >>> is_select(a)
5062 False
5063 >>> i = Int('i')
5064 >>> is_select(a[i])
5065 True
5066 """
5067 return is_app_of(a, Z3_OP_SELECT)
5068
5069

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

11238def is_seq(a):
11239 """Return `True` if `a` is a Z3 sequence expression.
11240 >>> print (is_seq(Unit(IntVal(0))))
11241 True
11242 >>> print (is_seq(StringVal("abc")))
11243 True
11244 """
11245 return isinstance(a, SeqRef)
11246
11247

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

685def is_sort(s : Any) -> bool:
686 """Return `True` if `s` is a Z3 sort.
687
688 >>> is_sort(IntSort())
689 True
690 >>> is_sort(Int('x'))
691 False
692 >>> is_expr(Int('x'))
693 True
694 """
695 return isinstance(s, SortRef)
696
697

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

5070def is_store(a):
5071 """Return `True` if `a` is a Z3 array store application.
5072
5073 >>> a = Array('a', IntSort(), IntSort())
5074 >>> is_store(a)
5075 False
5076 >>> is_store(Store(a, 0, 1))
5077 True
5078 """
5079 return is_app_of(a, Z3_OP_STORE)
5080

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

11248def is_string(a: Any) -> bool:
11249 """Return `True` if `a` is a Z3 string expression.
11250 >>> print (is_string(StringVal("ab")))
11251 True
11252 """
11253 return isinstance(a, SeqRef) and a.is_string()
11254
11255

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

11256def is_string_value(a: Any) -> bool:
11257 """return 'True' if 'a' is a Z3 string constant expression.
11258 >>> print (is_string_value(StringVal("a")))
11259 True
11260 >>> print (is_string_value(StringVal("a") + StringVal("b")))
11261 False
11262 """
11263 return isinstance(a, SeqRef) and a.is_string_value()
11264

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

2962def is_sub(a : Any) -> bool:
2963 """Return `True` if `a` is an expression of the form b - c.
2964
2965 >>> x, y = Ints('x y')
2966 >>> is_sub(x - y)
2967 True
2968 >>> is_sub(x + y)
2969 False
2970 """
2971 return is_app_of(a, Z3_OP_SUB)
2972
2973

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

3090def is_to_int(a : Any) -> bool:
3091 """Return `True` if `a` is an expression of the form ToInt(b).
3092
3093 >>> x = Real('x')
3094 >>> n = ToInt(x)
3095 >>> n
3096 ToInt(x)
3097 >>> is_to_int(n)
3098 True
3099 >>> is_to_int(x)
3100 False
3101 """
3102 return is_app_of(a, Z3_OP_TO_INT)
3103
3104

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

3075def is_to_real(a : Any) -> bool:
3076 """Return `True` if `a` is an expression of the form ToReal(b).
3077
3078 >>> x = Int('x')
3079 >>> n = ToReal(x)
3080 >>> n
3081 ToReal(x)
3082 >>> is_to_real(n)
3083 True
3084 >>> is_to_real(x)
3085 False
3086 """
3087 return is_app_of(a, Z3_OP_TO_REAL)
3088
3089

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

1725def is_true(a : Any) -> bool:
1726 """Return `True` if `a` is the Z3 true expression.
1727
1728 >>> p = Bool('p')
1729 >>> is_true(p)
1730 False
1731 >>> is_true(simplify(p == p))
1732 True
1733 >>> x = Real('x')
1734 >>> is_true(x == 0)
1735 False
1736 >>> # True is a Python Boolean expression
1737 >>> is_true(True)
1738 False
1739 """
1740 return is_app_of(a, Z3_OP_TRUE)
1741
1742

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

1416def is_var(a):
1417 """Return `True` if `a` is variable.
1418
1419 Z3 uses de-Bruijn indices for representing bound variables in
1420 quantifiers.
1421
1422 >>> x = Int('x')
1423 >>> is_var(x)
1424 False
1425 >>> is_const(x)
1426 True
1427 >>> f = Function('f', IntSort(), IntSort())
1428 >>> # Z3 replaces x with bound variables when ForAll is executed.
1429 >>> q = ForAll(x, f(x) == x)
1430 >>> b = q.body()
1431 >>> b
1432 f(Var(0)) == Var(0)
1433 >>> b.arg(1)
1434 Var(0)
1435 >>> is_var(b.arg(1))
1436 True
1437 """
1438 return is_expr(a) and _ast_kind(a.ctx, a) == Z3_VAR_AST
1439
1440

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

3544def IsInt(a):
3545 """ Return the Z3 predicate IsInt(a).
3546
3547 >>> x = Real('x')
3548 >>> IsInt(x + "1/2")
3549 IsInt(x + 1/2)
3550 >>> solve(IsInt(x + "1/2"), x > 0, x < 1)
3551 [x = 1/2]
3552 >>> solve(IsInt(x + "1/2"), x > 0, x < 1, x != "1/2")
3553 no solution
3554 """
3555 if z3_debug():
3556 _z3_assert(a.is_real(), "Z3 real expression expected.")
3557 ctx = a.ctx
3558 return BoolRef(Z3_mk_is_int(ctx.ref(), a.as_ast()), ctx)
3559
3560
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 5180 of file z3py.py.

5180def IsMember(e, s):
5181 """ Check if e is a member of set s
5182 >>> a = Const('a', SetSort(IntSort()))
5183 >>> IsMember(1, a)
5184 a[1]
5185 """
5186 ctx = _ctx_from_ast_arg_list([s, e])
5187 e = _py2expr(e, ctx)
5188 return BoolRef(Z3_mk_set_member(ctx.ref(), e.as_ast(), s.as_ast()), ctx)
5189
5190
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 5191 of file z3py.py.

5191def IsSubset(a, b):
5192 """ Check if a is a subset of b
5193 >>> a = Const('a', SetSort(IntSort()))
5194 >>> b = Const('b', SetSort(IntSort()))
5195 >>> IsSubset(a, b)
5196 subset(a, b)
5197 """
5198 ctx = _ctx_from_ast_arg_list([a, b])
5199 return BoolRef(Z3_mk_set_subset(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
5200
5201
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 5024 of file z3py.py.

5024def K(dom, v):
5025 """Return a Z3 constant array expression.
5026
5027 >>> a = K(IntSort(), 10)
5028 >>> a
5029 K(Int, 10)
5030 >>> a.sort()
5031 Array(Int, Int)
5032 >>> i = Int('i')
5033 >>> a[i]
5034 K(Int, 10)[i]
5035 >>> simplify(a[i])
5036 10
5037 """
5038 if z3_debug():
5039 _z3_assert(is_sort(dom), "Z3 sort expected")
5040 ctx = dom.ctx
5041 if not is_expr(v):
5042 v = _py2expr(v, ctx)
5043 return ArrayRef(Z3_mk_const_array(ctx.ref(), dom.ast, v.as_ast()), ctx)
5044
5045
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 2407 of file z3py.py.

2407def Lambda(vs, body):
2408 """Create a Z3 lambda expression.
2409
2410 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2411 >>> mem0 = Array('mem0', IntSort(), IntSort())
2412 >>> lo, hi, e, i = Ints('lo hi e i')
2413 >>> mem1 = Lambda([i], If(And(lo <= i, i <= hi), e, mem0[i]))
2414 >>> mem1
2415 Lambda(i, If(And(lo <= i, i <= hi), e, mem0[i]))
2416 """
2417 ctx = body.ctx
2418 if is_app(vs):
2419 vs = [vs]
2420 num_vars = len(vs)
2421 _vs = (Ast * num_vars)()
2422 for i in range(num_vars):
2423 # TODO: Check if is constant
2424 _vs[i] = vs[i].as_ast()
2425 return QuantifierRef(Z3_mk_lambda_const(ctx.ref(), num_vars, _vs, body.as_ast()), ctx)
2426
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 11441 of file z3py.py.

11441def LastIndexOf(s, substr):
11442 """Retrieve the last index of substring within a string"""
11443 ctx = None
11444 ctx = _get_ctx2(s, substr, ctx)
11445 s = _coerce_seq(s, ctx)
11446 substr = _coerce_seq(substr, ctx)
11447 return ArithRef(Z3_mk_seq_last_index(s.ctx_ref(), s.as_ast(), substr.as_ast()), s.ctx)
11448
11449
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 11450 of file z3py.py.

11450def Length(s):
11451 """Obtain the length of a sequence 's'
11452 >>> l = Length(StringVal("abc"))
11453 >>> simplify(l)
11454 3
11455 """
11456 s = _coerce_seq(s)
11457 return ArithRef(Z3_mk_seq_length(s.ctx_ref(), s.as_ast()), s.ctx)
11458
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 11712 of file z3py.py.

11712def LinearOrder(a, index):
11713 return FuncDeclRef(Z3_mk_linear_order(a.ctx_ref(), a.ast, index), a.ctx)
11714
11715
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 11662 of file z3py.py.

11662def Loop(re, lo, hi=0):
11663 """Create the regular expression accepting between a lower and upper bound repetitions
11664 >>> re = Loop(Re("a"), 1, 3)
11665 >>> print(simplify(InRe("aa", re)))
11666 True
11667 >>> print(simplify(InRe("aaaa", re)))
11668 False
11669 >>> print(simplify(InRe("", re)))
11670 False
11671 """
11672 if z3_debug():
11673 _z3_assert(is_expr(re), "expression expected")
11674 return ReRef(Z3_mk_re_loop(re.ctx_ref(), re.as_ast(), lo, hi), re.ctx)
11675
11676
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 4477 of file z3py.py.

4477def LShR(a, b):
4478 """Create the Z3 expression logical right shift.
4479
4480 Use the operator >> for the arithmetical right shift.
4481
4482 >>> x, y = BitVecs('x y', 32)
4483 >>> LShR(x, y)
4484 LShR(x, y)
4485 >>> (x >> y).sexpr()
4486 '(bvashr x y)'
4487 >>> LShR(x, y).sexpr()
4488 '(bvlshr x y)'
4489 >>> BitVecVal(4, 3)
4490 4
4491 >>> BitVecVal(4, 3).as_signed_long()
4492 -4
4493 >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
4494 -2
4495 >>> simplify(BitVecVal(4, 3) >> 1)
4496 6
4497 >>> simplify(LShR(BitVecVal(4, 3), 1))
4498 2
4499 >>> simplify(BitVecVal(2, 3) >> 1)
4500 1
4501 >>> simplify(LShR(BitVecVal(2, 3), 1))
4502 1
4503 """
4504 _check_bv_args(a, b)
4505 a, b = _coerce_exprs(a, b)
4506 return BitVecRef(Z3_mk_bvlshr(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4507
4508
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 269 of file z3py.py.

269def main_ctx() -> Context:
270 """Return a reference to the global Z3 context.
271
272 >>> x = Real('x')
273 >>> x.ctx == main_ctx()
274 True
275 >>> c = Context()
276 >>> c == main_ctx()
277 False
278 >>> x2 = Real('x', c)
279 >>> x2.ctx == c
280 True
281 >>> eq(x, x2)
282 False
283 """
284 global _main_ctx
285 if _main_ctx is None:
286 _main_ctx = Context()
287 return _main_ctx
288
289

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

5001def Map(f, *args):
5002 """Return a Z3 map array expression.
5003
5004 >>> f = Function('f', IntSort(), IntSort(), IntSort())
5005 >>> a1 = Array('a1', IntSort(), IntSort())
5006 >>> a2 = Array('a2', IntSort(), IntSort())
5007 >>> b = Map(f, a1, a2)
5008 >>> b
5009 Map(f, a1, a2)
5010 >>> prove(b[0] == f(a1[0], a2[0]))
5011 proved
5012 """
5013 args = _get_args(args)
5014 if z3_debug():
5015 _z3_assert(len(args) > 0, "At least one Z3 array expression expected")
5016 _z3_assert(is_func_decl(f), "First argument must be a Z3 function declaration")
5017 _z3_assert(all([is_array(a) for a in args]), "Z3 array expected expected")
5018 _z3_assert(len(args) == f.arity(), "Number of arguments mismatch")
5019 _args, sz = _to_ast_array(args)
5020 ctx = f.ctx
5021 return ArrayRef(Z3_mk_map(ctx.ref(), f.ast, sz, _args), ctx)
5022
5023
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 1970 of file z3py.py.

1970def mk_not(a):
1971 if is_not(a):
1972 return a.arg(0)
1973 else:
1974 return Not(a)
1975
1976

◆ Model()

Model (   ctx = None,
  eval = {} 
)

Definition at line 6904 of file z3py.py.

6904def Model(ctx=None, eval = {}):
6905 ctx = _get_ctx(ctx)
6906 mdl = ModelRef(Z3_mk_model(ctx.ref()), ctx)
6907 for k, v in eval.items():
6908 mdl.update_value(k, v)
6909 return mdl
6910
6911
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 2087 of file z3py.py.

2087def MultiPattern(*args):
2088 """Create a Z3 multi-pattern using the given expressions `*args`
2089
2090 >>> f = Function('f', IntSort(), IntSort())
2091 >>> g = Function('g', IntSort(), IntSort())
2092 >>> x = Int('x')
2093 >>> q = ForAll(x, f(x) != g(x), patterns = [ MultiPattern(f(x), g(x)) ])
2094 >>> q
2095 ForAll(x, f(x) != g(x))
2096 >>> q.num_patterns()
2097 1
2098 >>> is_pattern(q.pattern(0))
2099 True
2100 >>> q.pattern(0)
2101 MultiPattern(f(Var(0)), g(Var(0)))
2102 """
2103 if z3_debug():
2104 _z3_assert(len(args) > 0, "At least one argument expected")
2105 _z3_assert(all([is_expr(a) for a in args]), "Z3 expressions expected")
2106 ctx = args[0].ctx
2107 args, sz = _to_ast_array(args)
2108 return PatternRef(Z3_mk_pattern(ctx.ref(), sz, args), ctx)
2109
2110
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 1951 of file z3py.py.

1951def Not(a, ctx=None):
1952 """Create a Z3 not expression or probe.
1953
1954 >>> p = Bool('p')
1955 >>> Not(Not(p))
1956 Not(Not(p))
1957 >>> simplify(Not(Not(p)))
1958 p
1959 """
1960 ctx = _get_ctx(_ctx_from_ast_arg_list([a], ctx))
1961 if is_probe(a):
1962 # Not is also used to build probes
1963 return Probe(Z3_probe_not(ctx.ref(), a.probe), ctx)
1964 else:
1965 s = BoolSort(ctx)
1966 a = s.cast(a)
1967 return BoolRef(Z3_mk_not(ctx.ref(), a.as_ast()), ctx)
1968
1969
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 11752 of file z3py.py.

11752def on_clause_eh(ctx, p, n, dep, clause):
11753 onc = _my_hacky_class
11754 p = _to_expr_ref(to_Ast(p), onc.ctx)
11755 clause = AstVector(to_AstVectorObj(clause), onc.ctx)
11756 deps = [dep[i] for i in range(n)]
11757 onc.on_clause(p, deps, clause)
11758

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

11627def Option(re):
11628 """Create the regular expression that optionally accepts the argument.
11629 >>> re = Option(Re("a"))
11630 >>> print(simplify(InRe("a", re)))
11631 True
11632 >>> print(simplify(InRe("", re)))
11633 True
11634 >>> print(simplify(InRe("aa", re)))
11635 False
11636 """
11637 if z3_debug():
11638 _z3_assert(is_expr(re), "expression expected")
11639 return ReRef(Z3_mk_re_option(re.ctx_ref(), re.as_ast()), re.ctx)
11640
11641
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 2018 of file z3py.py.

2018def Or(*args):
2019 """Create a Z3 or-expression or or-probe.
2020
2021 >>> p, q, r = Bools('p q r')
2022 >>> Or(p, q, r)
2023 Or(p, q, r)
2024 >>> P = BoolVector('p', 5)
2025 >>> Or(P)
2026 Or(p__0, p__1, p__2, p__3, p__4)
2027 """
2028 last_arg = None
2029 if len(args) > 0:
2030 last_arg = args[len(args) - 1]
2031 if isinstance(last_arg, Context):
2032 ctx = args[len(args) - 1]
2033 args = args[:len(args) - 1]
2034 elif len(args) == 1 and isinstance(args[0], AstVector):
2035 ctx = args[0].ctx
2036 args = [a for a in args[0]]
2037 else:
2038 ctx = None
2039 args = _get_args(args)
2040 ctx = _get_ctx(_ctx_from_ast_arg_list(args, ctx))
2041 if z3_debug():
2042 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression or probe")
2043 if _has_probe(args):
2044 return _probe_or(args, ctx)
2045 else:
2046 args = _coerce_expr_list(args, ctx)
2047 _args, sz = _to_ast_array(args)
2048 return BoolRef(Z3_mk_or(ctx.ref(), sz, _args), ctx)
2049
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 8661 of file z3py.py.

8661def OrElse(*ts, **ks):
8662 """Return a tactic that applies the tactics in `*ts` until one of them succeeds (it doesn't fail).
8663
8664 >>> x = Int('x')
8665 >>> t = OrElse(Tactic('split-clause'), Tactic('skip'))
8666 >>> # Tactic split-clause fails if there is no clause in the given goal.
8667 >>> t(x == 0)
8668 [[x == 0]]
8669 >>> t(Or(x == 0, x == 1))
8670 [[x == 0], [x == 1]]
8671 """
8672 if z3_debug():
8673 _z3_assert(len(ts) >= 2, "At least two arguments expected")
8674 ctx = ks.get("ctx", None)
8675 num = len(ts)
8676 r = ts[0]
8677 for i in range(num - 1):
8678 r = _or_else(r, ts[i + 1], ctx)
8679 return r
8680
8681

◆ ParAndThen()

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

Definition at line 8717 of file z3py.py.

8717def ParAndThen(t1, t2, ctx=None):
8718 """Alias for ParThen(t1, t2, ctx)."""
8719 return ParThen(t1, t2, ctx)
8720
8721

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

8682def ParOr(*ts, **ks):
8683 """Return a tactic that applies the tactics in `*ts` in parallel until one of them succeeds (it doesn't fail).
8684
8685 >>> x = Int('x')
8686 >>> t = ParOr(Tactic('simplify'), Tactic('fail'))
8687 >>> t(x + 1 == 2)
8688 [[x == 1]]
8689 """
8690 if z3_debug():
8691 _z3_assert(len(ts) >= 2, "At least two arguments expected")
8692 ctx = _get_ctx(ks.get("ctx", None))
8693 ts = [_to_tactic(t, ctx) for t in ts]
8694 sz = len(ts)
8695 _args = (TacticObj * sz)()
8696 for i in range(sz):
8697 _args[i] = ts[i].tactic
8698 return Tactic(Z3_tactic_par_or(ctx.ref(), sz, _args), ctx)
8699
8700
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 9597 of file z3py.py.

9597def parse_smt2_file(f, sorts={}, decls={}, ctx=None):
9598 """Parse a file in SMT 2.0 format using the given sorts and decls.
9599
9600 This function is similar to parse_smt2_string().
9601 """
9602 ctx = _get_ctx(ctx)
9603 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
9604 dsz, dnames, ddecls = _dict2darray(decls, ctx)
9605 return AstVector(Z3_parse_smtlib2_file(ctx.ref(), f, ssz, snames, ssorts, dsz, dnames, ddecls), ctx)
9606
9607
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 9576 of file z3py.py.

9576def parse_smt2_string(s, sorts={}, decls={}, ctx=None):
9577 """Parse a string in SMT 2.0 format using the given sorts and decls.
9578
9579 The arguments sorts and decls are Python dictionaries used to initialize
9580 the symbol table used for the SMT 2.0 parser.
9581
9582 >>> parse_smt2_string('(declare-const x Int) (assert (> x 0)) (assert (< x 10))')
9583 [x > 0, x < 10]
9584 >>> x, y = Ints('x y')
9585 >>> f = Function('f', IntSort(), IntSort())
9586 >>> parse_smt2_string('(assert (> (+ foo (g bar)) 0))', decls={ 'foo' : x, 'bar' : y, 'g' : f})
9587 [x + f(y) > 0]
9588 >>> parse_smt2_string('(declare-const a U) (assert (> a 0))', sorts={ 'U' : IntSort() })
9589 [a > 0]
9590 """
9591 ctx = _get_ctx(ctx)
9592 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
9593 dsz, dnames, ddecls = _dict2darray(decls, ctx)
9594 return AstVector(Z3_parse_smtlib2_string(ctx.ref(), s, ssz, snames, ssorts, dsz, dnames, ddecls), ctx)
9595
9596
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 8701 of file z3py.py.

8701def ParThen(t1, t2, ctx=None):
8702 """Return a tactic that applies t1 and then t2 to every subgoal produced by t1.
8703 The subgoals are processed in parallel.
8704
8705 >>> x, y = Ints('x y')
8706 >>> t = ParThen(Tactic('split-clause'), Tactic('propagate-values'))
8707 >>> t(And(Or(x == 1, x == 2), y == x + 1))
8708 [[x == 1, y == 2], [x == 2, y == 3]]
8709 """
8710 t1 = _to_tactic(t1, ctx)
8711 t2 = _to_tactic(t2, ctx)
8712 if z3_debug():
8713 _z3_assert(t1.ctx == t2.ctx, "Context mismatch")
8714 return Tactic(Z3_tactic_par_and_then(t1.ctx.ref(), t1.tactic, t2.tactic), t1.ctx)
8715
8716
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 11708 of file z3py.py.

11708def PartialOrder(a, index):
11709 return FuncDeclRef(Z3_mk_partial_order(a.ctx_ref(), a.ast, index), a.ctx)
11710
11711
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 9353 of file z3py.py.

9353def PbEq(args, k, ctx=None):
9354 """Create a Pseudo-Boolean equality k constraint.
9355
9356 >>> a, b, c = Bools('a b c')
9357 >>> f = PbEq(((a,1),(b,3),(c,2)), 3)
9358 """
9359 _z3_check_cint_overflow(k, "k")
9360 ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
9361 return BoolRef(Z3_mk_pbeq(ctx.ref(), sz, _args, _coeffs, k), ctx)
9362
9363
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 9342 of file z3py.py.

9342def PbGe(args, k):
9343 """Create a Pseudo-Boolean inequality k constraint.
9344
9345 >>> a, b, c = Bools('a b c')
9346 >>> f = PbGe(((a,1),(b,3),(c,2)), 3)
9347 """
9348 _z3_check_cint_overflow(k, "k")
9349 ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
9350 return BoolRef(Z3_mk_pbge(ctx.ref(), sz, _args, _coeffs, k), ctx)
9351
9352
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 9331 of file z3py.py.

9331def PbLe(args, k):
9332 """Create a Pseudo-Boolean inequality k constraint.
9333
9334 >>> a, b, c = Bools('a b c')
9335 >>> f = PbLe(((a,1),(b,3),(c,2)), 3)
9336 """
9337 _z3_check_cint_overflow(k, "k")
9338 ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
9339 return BoolRef(Z3_mk_pble(ctx.ref(), sz, _args, _coeffs, k), ctx)
9340
9341
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 11720 of file z3py.py.

11720def PiecewiseLinearOrder(a, index):
11721 return FuncDeclRef(Z3_mk_piecewise_linear_order(a.ctx_ref(), a.ast, index), a.ctx)
11722
11723
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 11612 of file z3py.py.

11612def Plus(re):
11613 """Create the regular expression accepting one or more repetitions of argument.
11614 >>> re = Plus(Re("a"))
11615 >>> print(simplify(InRe("aa", re)))
11616 True
11617 >>> print(simplify(InRe("ab", re)))
11618 False
11619 >>> print(simplify(InRe("", re)))
11620 False
11621 """
11622 if z3_debug():
11623 _z3_assert(is_expr(re), "expression expected")
11624 return ReRef(Z3_mk_re_plus(re.ctx_ref(), re.as_ast()), re.ctx)
11625
11626
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 11357 of file z3py.py.

11357def PrefixOf(a, b):
11358 """Check if 'a' is a prefix of 'b'
11359 >>> s1 = PrefixOf("ab", "abc")
11360 >>> simplify(s1)
11361 True
11362 >>> s2 = PrefixOf("bc", "abc")
11363 >>> simplify(s2)
11364 False
11365 """
11366 ctx = _get_ctx2(a, b)
11367 a = _coerce_seq(a, ctx)
11368 b = _coerce_seq(b, ctx)
11369 return BoolRef(Z3_mk_seq_prefix(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
11370
11371
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 8997 of file z3py.py.

8997def probe_description(name, ctx=None):
8998 """Return a short description for the probe named `name`.
8999
9000 >>> d = probe_description('memory')
9001 """
9002 ctx = _get_ctx(ctx)
9003 return Z3_probe_get_descr(ctx.ref(), name)
9004
9005
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 8986 of file z3py.py.

8986def probes(ctx=None):
8987 """Return a list of all available probes in Z3.
8988
8989 >>> l = probes()
8990 >>> l.count('memory') == 1
8991 True
8992 """
8993 ctx = _get_ctx(ctx)
8994 return [Z3_get_probe_name(ctx.ref(), i) for i in range(Z3_get_num_probes(ctx.ref()))]
8995
8996
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 9238 of file z3py.py.

9238def Product(*args):
9239 """Create the product of the Z3 expressions.
9240
9241 >>> a, b, c = Ints('a b c')
9242 >>> Product(a, b, c)
9243 a*b*c
9244 >>> Product([a, b, c])
9245 a*b*c
9246 >>> A = IntVector('a', 5)
9247 >>> Product(A)
9248 a__0*a__1*a__2*a__3*a__4
9249 """
9250 args = _get_args(args)
9251 if len(args) == 0:
9252 return 1
9253 ctx = _ctx_from_ast_arg_list(args)
9254 if ctx is None:
9255 return _reduce(lambda a, b: a * b, args, 1)
9256 args = _coerce_expr_list(args, ctx)
9257 if is_bv(args[0]):
9258 return _reduce(lambda a, b: a * b, args, 1)
9259 else:
9260 _args, sz = _to_ast_array(args)
9261 return ArithRef(Z3_mk_mul(ctx.ref(), sz, _args), ctx)
9262
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 11917 of file z3py.py.

11917def PropagateFunction(name, *sig):
11918 """Create a function that gets tracked by user propagator.
11919 Every term headed by this function symbol is tracked.
11920 If a term is fixed and the fixed callback is registered a
11921 callback is invoked that the term headed by this function is fixed.
11922 """
11923 sig = _get_args(sig)
11924 if z3_debug():
11925 _z3_assert(len(sig) > 0, "At least two arguments expected")
11926 arity = len(sig) - 1
11927 rng = sig[arity]
11928 if z3_debug():
11929 _z3_assert(is_sort(rng), "Z3 sort expected")
11930 dom = (Sort * arity)()
11931 for i in range(arity):
11932 if z3_debug():
11933 _z3_assert(is_sort(sig[i]), "Z3 sort expected")
11934 dom[i] = sig[i].ast
11935 ctx = rng.ctx
11936 return FuncDeclRef(Z3_solver_propagate_declare(ctx.ref(), to_symbol(name, ctx), arity, dom, rng.ast), ctx)
11937
11938
11939
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 9425 of file z3py.py.

9425def prove(claim, show=False, **keywords):
9426 """Try to prove the given claim.
9427
9428 This is a simple function for creating demonstrations. It tries to prove
9429 `claim` by showing the negation is unsatisfiable.
9430
9431 >>> p, q = Bools('p q')
9432 >>> prove(Not(And(p, q)) == Or(Not(p), Not(q)))
9433 proved
9434 """
9435 if z3_debug():
9436 _z3_assert(is_bool(claim), "Z3 Boolean expression expected")
9437 s = Solver()
9438 s.set(**keywords)
9439 s.add(Not(claim))
9440 if show:
9441 print(s)
9442 r = s.check()
9443 if r == unsat:
9444 print("proved")
9445 elif r == unknown:
9446 print("failed to prove")
9447 print(s.model())
9448 else:
9449 print("counterexample")
9450 print(s.model())
9451
9452

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

3383def Q(a, b, ctx=None):
3384 """Return a Z3 rational a/b.
3385
3386 If `ctx=None`, then the global context is used.
3387
3388 >>> Q(3,5)
3389 3/5
3390 >>> Q(3,5).sort()
3391 Real
3392 """
3393 return simplify(RatVal(a, b, ctx=ctx))
3394
3395

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

11677def Range(lo, hi, ctx=None):
11678 """Create the range regular expression over two sequences of length 1
11679 >>> range = Range("a","z")
11680 >>> print(simplify(InRe("b", range)))
11681 True
11682 >>> print(simplify(InRe("bb", range)))
11683 False
11684 """
11685 lo = _coerce_seq(lo, ctx)
11686 hi = _coerce_seq(hi, ctx)
11687 if z3_debug():
11688 _z3_assert(is_expr(lo), "expression expected")
11689 _z3_assert(is_expr(hi), "expression expected")
11690 return ReRef(Z3_mk_re_range(lo.ctx_ref(), lo.ast, hi.ast), lo.ctx)
11691
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 3367 of file z3py.py.

3367def RatVal(a, b, ctx=None):
3368 """Return a Z3 rational a/b.
3369
3370 If `ctx=None`, then the global context is used.
3371
3372 >>> RatVal(3,5)
3373 3/5
3374 >>> RatVal(3,5).sort()
3375 Real
3376 """
3377 if z3_debug():
3378 _z3_assert(_is_int(a) or isinstance(a, str), "First argument cannot be converted into an integer")
3379 _z3_assert(_is_int(b) or isinstance(b, str), "Second argument cannot be converted into an integer")
3380 return simplify(RealVal(a, ctx) / RealVal(b, ctx))
3381
3382

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

11521def Re(s, ctx=None):
11522 """The regular expression that accepts sequence 's'
11523 >>> s1 = Re("ab")
11524 >>> s2 = Re(StringVal("ab"))
11525 >>> s3 = Re(Unit(BoolVal(True)))
11526 """
11527 s = _coerce_seq(s, ctx)
11528 return ReRef(Z3_mk_seq_to_re(s.ctx_ref(), s.as_ast()), s.ctx)
11529
11530
11531# Regular expressions
11532
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 3449 of file z3py.py.

3449def Real(name, ctx=None):
3450 """Return a real constant named `name`. If `ctx=None`, then the global context is used.
3451
3452 >>> x = Real('x')
3453 >>> is_real(x)
3454 True
3455 >>> is_real(x + 1)
3456 True
3457 """
3458 ctx = _get_ctx(ctx)
3459 return ArithRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), RealSort(ctx).ast), ctx)
3460
3461

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

3462def Reals(names, ctx=None):
3463 """Return a tuple of real constants.
3464
3465 >>> x, y, z = Reals('x y z')
3466 >>> Sum(x, y, z)
3467 x + y + z
3468 >>> Sum(x, y, z).sort()
3469 Real
3470 """
3471 ctx = _get_ctx(ctx)
3472 if isinstance(names, str):
3473 names = names.split(" ")
3474 return [Real(name, ctx) for name in names]
3475
3476

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

3307def RealSort(ctx=None):
3308 """Return the real sort in the given context. If `ctx=None`, then the global context is used.
3309
3310 >>> RealSort()
3311 Real
3312 >>> x = Const('x', RealSort())
3313 >>> is_real(x)
3314 True
3315 >>> is_int(x)
3316 False
3317 >>> x.sort() == RealSort()
3318 True
3319 """
3320 ctx = _get_ctx(ctx)
3321 return ArithSortRef(Z3_mk_real_sort(ctx.ref()), ctx)
3322
3323
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 3348 of file z3py.py.

3348def RealVal(val, ctx=None):
3349 """Return a Z3 real value.
3350
3351 `val` may be a Python int, long, float or string representing a number in decimal or rational notation.
3352 If `ctx=None`, then the global context is used.
3353
3354 >>> RealVal(1)
3355 1
3356 >>> RealVal(1).sort()
3357 Real
3358 >>> RealVal("3/5")
3359 3/5
3360 >>> RealVal("1.5")
3361 3/2
3362 """
3363 ctx = _get_ctx(ctx)
3364 return RatNumRef(Z3_mk_numeral(ctx.ref(), str(val), RealSort(ctx).ast), ctx)
3365
3366

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

1593def RealVar(idx: int, ctx=None) -> ExprRef:
1594 """
1595 Create a real free variable. Free variables are used to create quantified formulas.
1596 They are also used to create polynomials.
1597
1598 >>> RealVar(0)
1599 Var(0)
1600 """
1601 return Var(idx, RealSort(ctx))
1602

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

1603def RealVarVector(n: int, ctx= None):
1604 """
1605 Create a list of Real free variables.
1606 The variables have ids: 0, 1, ..., n-1
1607
1608 >>> x0, x1, x2, x3 = RealVarVector(4)
1609 >>> x2
1610 Var(2)
1611 """
1612 return [RealVar(i, ctx) for i in range(n)]
1613

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

3477def RealVector(prefix, sz, ctx=None):
3478 """Return a list of real constants of size `sz`.
3479
3480 >>> X = RealVector('x', 3)
3481 >>> X
3482 [x__0, x__1, x__2]
3483 >>> Sum(X)
3484 x__0 + x__1 + x__2
3485 >>> Sum(X).sort()
3486 Real
3487 """
3488 ctx = _get_ctx(ctx)
3489 return [Real("%s__%s" % (prefix, i), ctx) for i in range(sz)]
3490
3491

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

987def RecAddDefinition(f, args, body):
988 """Set the body of a recursive function.
989 Recursive definitions can be simplified if they are applied to ground
990 arguments.
991 >>> ctx = Context()
992 >>> fac = RecFunction('fac', IntSort(ctx), IntSort(ctx))
993 >>> n = Int('n', ctx)
994 >>> RecAddDefinition(fac, n, If(n == 0, 1, n*fac(n-1)))
995 >>> simplify(fac(5))
996 120
997 >>> s = Solver(ctx=ctx)
998 >>> s.add(fac(n) < 3)
999 >>> s.check()
1000 sat
1001 >>> s.model().eval(fac(5))
1002 120
1003 """
1004 if is_app(args):
1005 args = [args]
1006 ctx = body.ctx
1007 args = _get_args(args)
1008 n = len(args)
1009 _args = (Ast * n)()
1010 for i in range(n):
1011 _args[i] = args[i].ast
1012 Z3_add_rec_def(ctx.ref(), f.ast, n, _args, body.ast)
1013
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 969 of file z3py.py.

969def RecFunction(name, *sig):
970 """Create a new Z3 recursive with the given sorts."""
971 sig = _get_args(sig)
972 if z3_debug():
973 _z3_assert(len(sig) > 0, "At least two arguments expected")
974 arity = len(sig) - 1
975 rng = sig[arity]
976 if z3_debug():
977 _z3_assert(is_sort(rng), "Z3 sort expected")
978 dom = (Sort * arity)()
979 for i in range(arity):
980 if z3_debug():
981 _z3_assert(is_sort(sig[i]), "Z3 sort expected")
982 dom[i] = sig[i].ast
983 ctx = rng.ctx
984 return FuncDeclRef(Z3_mk_rec_func_decl(ctx.ref(), to_symbol(name, ctx), arity, dom, rng.ast), ctx)
985
986
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 8750 of file z3py.py.

8750def Repeat(t, max=4294967295, ctx=None):
8751 """Return a tactic that keeps applying `t` until the goal is not modified anymore
8752 or the maximum number of iterations `max` is reached.
8753
8754 >>> x, y = Ints('x y')
8755 >>> c = And(Or(x == 0, x == 1), Or(y == 0, y == 1), x > y)
8756 >>> t = Repeat(OrElse(Tactic('split-clause'), Tactic('skip')))
8757 >>> r = t(c)
8758 >>> for subgoal in r: print(subgoal)
8759 [x == 0, y == 0, x > y]
8760 [x == 0, y == 1, x > y]
8761 [x == 1, y == 0, x > y]
8762 [x == 1, y == 1, x > y]
8763 >>> t = Then(t, Tactic('propagate-values'))
8764 >>> t(c)
8765 [[x == 1, y == 0]]
8766 """
8767 t = _to_tactic(t, ctx)
8768 return Tactic(Z3_tactic_repeat(t.ctx.ref(), t.tactic, max), t.ctx)
8769
8770
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 4599 of file z3py.py.

4599def RepeatBitVec(n, a):
4600 """Return an expression representing `n` copies of `a`.
4601
4602 >>> x = BitVec('x', 8)
4603 >>> n = RepeatBitVec(4, x)
4604 >>> n
4605 RepeatBitVec(4, x)
4606 >>> n.size()
4607 32
4608 >>> v0 = BitVecVal(10, 4)
4609 >>> print("%.x" % v0.as_long())
4610 a
4611 >>> v = simplify(RepeatBitVec(4, v0))
4612 >>> v.size()
4613 16
4614 >>> print("%.x" % v.as_long())
4615 aaaa
4616 """
4617 if z3_debug():
4618 _z3_assert(_is_int(n), "First argument must be an integer")
4619 _z3_assert(is_bv(a), "Second argument must be a Z3 bit-vector expression")
4620 return BitVecRef(Z3_mk_repeat(a.ctx_ref(), n, a.as_ast()), a.ctx)
4621
4622
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 11406 of file z3py.py.

11406def Replace(s, src, dst):
11407 """Replace the first occurrence of 'src' by 'dst' in 's'
11408 >>> r = Replace("aaa", "a", "b")
11409 >>> simplify(r)
11410 "baa"
11411 """
11412 ctx = _get_ctx2(dst, s)
11413 if ctx is None and is_expr(src):
11414 ctx = src.ctx
11415 src = _coerce_seq(src, ctx)
11416 dst = _coerce_seq(dst, ctx)
11417 s = _coerce_seq(s, ctx)
11418 return SeqRef(Z3_mk_seq_replace(src.ctx_ref(), s.as_ast(), src.as_ast(), dst.as_ast()), s.ctx)
11419
11420
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 325 of file z3py.py.

325def reset_params() -> None:
326 """Reset all global (or module) parameters.
327 """
329
330
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 11540 of file z3py.py.

11540def ReSort(s):
11541 if is_ast(s):
11542 return ReSortRef(Z3_mk_re_sort(s.ctx.ref(), s.ast), s.ctx)
11543 if s is None or isinstance(s, Context):
11544 ctx = _get_ctx(s)
11545 return ReSortRef(Z3_mk_re_sort(ctx.ref(), Z3_mk_string_sort(ctx.ref())), s.ctx)
11546 raise Z3Exception("Regular expression sort constructor expects either a string or a context or no argument")
11547
11548
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 10012 of file z3py.py.

10012def RNA(ctx=None):
10013 ctx = _get_ctx(ctx)
10014 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_away(ctx.ref()), ctx)
10015
10016
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 10002 of file z3py.py.

10002def RNE(ctx=None):
10003 ctx = _get_ctx(ctx)
10004 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_even(ctx.ref()), ctx)
10005
10006
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 4509 of file z3py.py.

4509def RotateLeft(a, b):
4510 """Return an expression representing `a` rotated to the left `b` times.
4511
4512 >>> a, b = BitVecs('a b', 16)
4513 >>> RotateLeft(a, b)
4514 RotateLeft(a, b)
4515 >>> simplify(RotateLeft(a, 0))
4516 a
4517 >>> simplify(RotateLeft(a, 16))
4518 a
4519 """
4520 _check_bv_args(a, b)
4521 a, b = _coerce_exprs(a, b)
4522 return BitVecRef(Z3_mk_ext_rotate_left(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4523
4524
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 4525 of file z3py.py.

4525def RotateRight(a, b):
4526 """Return an expression representing `a` rotated to the right `b` times.
4527
4528 >>> a, b = BitVecs('a b', 16)
4529 >>> RotateRight(a, b)
4530 RotateRight(a, b)
4531 >>> simplify(RotateRight(a, 0))
4532 a
4533 >>> simplify(RotateRight(a, 16))
4534 a
4535 """
4536 _check_bv_args(a, b)
4537 a, b = _coerce_exprs(a, b)
4538 return BitVecRef(Z3_mk_ext_rotate_right(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4539
4540
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 10007 of file z3py.py.

10007def RoundNearestTiesToAway(ctx=None):
10008 ctx = _get_ctx(ctx)
10009 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_away(ctx.ref()), ctx)
10010
10011

◆ RoundNearestTiesToEven()

RoundNearestTiesToEven (   ctx = None)

Definition at line 9997 of file z3py.py.

9997def RoundNearestTiesToEven(ctx=None):
9998 ctx = _get_ctx(ctx)
9999 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_even(ctx.ref()), ctx)
10000
10001

◆ RoundTowardNegative()

RoundTowardNegative (   ctx = None)

Definition at line 10027 of file z3py.py.

10027def RoundTowardNegative(ctx=None):
10028 ctx = _get_ctx(ctx)
10029 return FPRMRef(Z3_mk_fpa_round_toward_negative(ctx.ref()), ctx)
10030
10031
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 10017 of file z3py.py.

10017def RoundTowardPositive(ctx=None):
10018 ctx = _get_ctx(ctx)
10019 return FPRMRef(Z3_mk_fpa_round_toward_positive(ctx.ref()), ctx)
10020
10021
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 10037 of file z3py.py.

10037def RoundTowardZero(ctx=None):
10038 ctx = _get_ctx(ctx)
10039 return FPRMRef(Z3_mk_fpa_round_toward_zero(ctx.ref()), ctx)
10040
10041
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 10032 of file z3py.py.

10032def RTN(ctx=None):
10033 ctx = _get_ctx(ctx)
10034 return FPRMRef(Z3_mk_fpa_round_toward_negative(ctx.ref()), ctx)
10035
10036

◆ RTP()

RTP (   ctx = None)

Definition at line 10022 of file z3py.py.

10022def RTP(ctx=None):
10023 ctx = _get_ctx(ctx)
10024 return FPRMRef(Z3_mk_fpa_round_toward_positive(ctx.ref()), ctx)
10025
10026

◆ RTZ()

RTZ (   ctx = None)

Definition at line 10042 of file z3py.py.

10042def RTZ(ctx=None):
10043 ctx = _get_ctx(ctx)
10044 return FPRMRef(Z3_mk_fpa_round_toward_zero(ctx.ref()), ctx)
10045
10046

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

4985def Select(a, *args):
4986 """Return a Z3 select array expression.
4987
4988 >>> a = Array('a', IntSort(), IntSort())
4989 >>> i = Int('i')
4990 >>> Select(a, i)
4991 a[i]
4992 >>> eq(Select(a, i), a[i])
4993 True
4994 """
4995 args = _get_args(args)
4996 if z3_debug():
4997 _z3_assert(is_array_sort(a), "First argument must be a Z3 array expression")
4998 return a[args]
4999
5000

◆ SeqFoldLeft()

SeqFoldLeft (   f,
  a,
  s 
)

Definition at line 11473 of file z3py.py.

11473def SeqFoldLeft(f, a, s):
11474 ctx = _get_ctx2(f, s)
11475 s = _coerce_seq(s, ctx)
11476 a = _py2expr(a)
11477 return _to_expr_ref(Z3_mk_seq_foldl(s.ctx_ref(), f.as_ast(), a.as_ast(), s.as_ast()), ctx)
11478
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 11479 of file z3py.py.

11479def SeqFoldLeftI(f, i, a, s):
11480 ctx = _get_ctx2(f, s)
11481 s = _coerce_seq(s, ctx)
11482 a = _py2expr(a)
11483 i = _py2expr(i)
11484 return _to_expr_ref(Z3_mk_seq_foldli(s.ctx_ref(), f.as_ast(), i.as_ast(), a.as_ast(), s.as_ast()), ctx)
11485
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 11459 of file z3py.py.

11459def SeqMap(f, s):
11460 """Map function 'f' over sequence 's'"""
11461 ctx = _get_ctx2(f, s)
11462 s = _coerce_seq(s, ctx)
11463 return _to_expr_ref(Z3_mk_seq_map(s.ctx_ref(), f.as_ast(), s.as_ast()), ctx)
11464
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 11465 of file z3py.py.

11465def SeqMapI(f, i, s):
11466 """Map function 'f' over sequence 's' at index 'i'"""
11467 ctx = _get_ctx2(f, s)
11468 s = _coerce_seq(s, ctx)
11469 if not is_expr(i):
11470 i = _py2expr(i)
11471 return _to_expr_ref(Z3_mk_seq_mapi(s.ctx_ref(), f.as_ast(), i.as_ast(), s.as_ast()), ctx)
11472
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 11106 of file z3py.py.

11106def SeqSort(s):
11107 """Create a sequence sort over elements provided in the argument
11108 >>> s = SeqSort(IntSort())
11109 >>> s == Unit(IntVal(1)).sort()
11110 True
11111 """
11112 return SeqSortRef(Z3_mk_seq_sort(s.ctx_ref(), s.ast), s.ctx)
11113
11114
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 9658 of file z3py.py.

9658def set_default_fp_sort(ebits, sbits, ctx=None):
9659 global _dflt_fpsort_ebits
9660 global _dflt_fpsort_sbits
9661 _dflt_fpsort_ebits = ebits
9662 _dflt_fpsort_sbits = sbits
9663
9664

◆ set_default_rounding_mode()

set_default_rounding_mode (   rm,
  ctx = None 
)

Definition at line 9645 of file z3py.py.

9645def set_default_rounding_mode(rm, ctx=None):
9646 global _dflt_rounding_mode
9647 if is_fprm_value(rm):
9648 _dflt_rounding_mode = rm.kind()
9649 else:
9650 _z3_assert(_dflt_rounding_mode in _ROUNDING_MODES, "illegal rounding mode")
9651 _dflt_rounding_mode = rm
9652
9653

◆ set_option()

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

Definition at line 331 of file z3py.py.

331def set_option(*args, **kws):
332 """Alias for 'set_param' for backward compatibility.
333 """
334 return set_param(*args, **kws)
335
336

◆ set_param()

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

>>> set_param(precision=10)

Definition at line 301 of file z3py.py.

301def set_param(*args, **kws):
302 """Set Z3 global (or module) parameters.
303
304 >>> set_param(precision=10)
305 """
306 if z3_debug():
307 _z3_assert(len(args) % 2 == 0, "Argument list must have an even number of elements.")
308 new_kws = {}
309 for k in kws:
310 v = kws[k]
311 if not set_pp_option(k, v):
312 new_kws[k] = v
313 for key in new_kws:
314 value = new_kws[key]
315 Z3_global_param_set(str(key).upper(), _to_param_value(value))
316 prev = None
317 for a in args:
318 if prev is None:
319 prev = a
320 else:
321 Z3_global_param_set(str(prev), _to_param_value(a))
322 prev = None
323
324
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 5137 of file z3py.py.

5137def SetAdd(s, e):
5138 """ Add element e to set s
5139 >>> a = Const('a', SetSort(IntSort()))
5140 >>> SetAdd(a, 1)
5141 Store(a, 1, True)
5142 """
5143 ctx = _ctx_from_ast_arg_list([s, e])
5144 e = _py2expr(e, ctx)
5145 return ArrayRef(Z3_mk_set_add(ctx.ref(), s.as_ast(), e.as_ast()), ctx)
5146
5147
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 5159 of file z3py.py.

5159def SetComplement(s):
5160 """ The complement of set s
5161 >>> a = Const('a', SetSort(IntSort()))
5162 >>> SetComplement(a)
5163 complement(a)
5164 """
5165 ctx = s.ctx
5166 return ArrayRef(Z3_mk_set_complement(ctx.ref(), s.as_ast()), ctx)
5167
5168
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 5148 of file z3py.py.

5148def SetDel(s, e):
5149 """ Remove element e to set s
5150 >>> a = Const('a', SetSort(IntSort()))
5151 >>> SetDel(a, 1)
5152 Store(a, 1, False)
5153 """
5154 ctx = _ctx_from_ast_arg_list([s, e])
5155 e = _py2expr(e, ctx)
5156 return ArrayRef(Z3_mk_set_del(ctx.ref(), s.as_ast(), e.as_ast()), ctx)
5157
5158
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 5169 of file z3py.py.

5169def SetDifference(a, b):
5170 """ The set difference of a and b
5171 >>> a = Const('a', SetSort(IntSort()))
5172 >>> b = Const('b', SetSort(IntSort()))
5173 >>> SetDifference(a, b)
5174 setminus(a, b)
5175 """
5176 ctx = _ctx_from_ast_arg_list([a, b])
5177 return ArrayRef(Z3_mk_set_difference(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
5178
5179
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 5124 of file z3py.py.

5124def SetIntersect(*args):
5125 """ Take the union of sets
5126 >>> a = Const('a', SetSort(IntSort()))
5127 >>> b = Const('b', SetSort(IntSort()))
5128 >>> SetIntersect(a, b)
5129 intersection(a, b)
5130 """
5131 args = _get_args(args)
5132 ctx = _ctx_from_ast_arg_list(args)
5133 _args, sz = _to_ast_array(args)
5134 return ArrayRef(Z3_mk_set_intersect(ctx.ref(), sz, _args), ctx)
5135
5136
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 5088 of file z3py.py.

5088def SetSort(s):
5089 """ Create a set sort over element sort s"""
5090 return ArraySort(s, BoolSort())
5091
5092

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

5111def SetUnion(*args):
5112 """ Take the union of sets
5113 >>> a = Const('a', SetSort(IntSort()))
5114 >>> b = Const('b', SetSort(IntSort()))
5115 >>> SetUnion(a, b)
5116 union(a, b)
5117 """
5118 args = _get_args(args)
5119 ctx = _ctx_from_ast_arg_list(args)
5120 _args, sz = _to_ast_array(args)
5121 return ArrayRef(Z3_mk_set_union(ctx.ref(), sz, _args), ctx)
5122
5123
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 4541 of file z3py.py.

4541def SignExt(n, a):
4542 """Return a bit-vector expression with `n` extra sign-bits.
4543
4544 >>> x = BitVec('x', 16)
4545 >>> n = SignExt(8, x)
4546 >>> n.size()
4547 24
4548 >>> n
4549 SignExt(8, x)
4550 >>> n.sort()
4551 BitVec(24)
4552 >>> v0 = BitVecVal(2, 2)
4553 >>> v0
4554 2
4555 >>> v0.size()
4556 2
4557 >>> v = simplify(SignExt(6, v0))
4558 >>> v
4559 254
4560 >>> v.size()
4561 8
4562 >>> print("%.x" % v.as_long())
4563 fe
4564 """
4565 if z3_debug():
4566 _z3_assert(_is_int(n), "First argument must be an integer")
4567 _z3_assert(is_bv(a), "Second argument must be a Z3 bit-vector expression")
4568 return BitVecRef(Z3_mk_sign_ext(a.ctx_ref(), n, a.as_ast()), a.ctx)
4569
4570
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 7677 of file z3py.py.

7677def SimpleSolver(ctx=None, logFile=None):
7678 """Return a simple general purpose solver with limited amount of preprocessing.
7679
7680 >>> s = SimpleSolver()
7681 >>> x = Int('x')
7682 >>> s.add(x > 0)
7683 >>> s.check()
7684 sat
7685 """
7686 ctx = _get_ctx(ctx)
7687 return Solver(Z3_mk_simple_solver(ctx.ref()), ctx, logFile)
7688
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 9102 of file z3py.py.

9102def simplify(a, *arguments, **keywords):
9103 """Simplify the expression `a` using the given options.
9104
9105 This function has many options. Use `help_simplify` to obtain the complete list.
9106
9107 >>> x = Int('x')
9108 >>> y = Int('y')
9109 >>> simplify(x + 1 + y + x + 1)
9110 2 + 2*x + y
9111 >>> simplify((x + 1)*(y + 1), som=True)
9112 1 + x + y + x*y
9113 >>> simplify(Distinct(x, y, 1), blast_distinct=True)
9114 And(Not(x == y), Not(x == 1), Not(y == 1))
9115 >>> simplify(And(x == 0, y == 1), elim_and=True)
9116 Not(Or(Not(x == 0), Not(y == 1)))
9117 """
9118 if z3_debug():
9119 _z3_assert(is_expr(a), "Z3 expression expected")
9120 if len(arguments) > 0 or len(keywords) > 0:
9121 p = args2params(arguments, keywords, a.ctx)
9122 return _to_expr_ref(Z3_simplify_ex(a.ctx_ref(), a.as_ast(), p.params), a.ctx)
9123 else:
9124 return _to_expr_ref(Z3_simplify(a.ctx_ref(), a.as_ast()), a.ctx)
9125
9126
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 9132 of file z3py.py.

9132def simplify_param_descrs():
9133 """Return the set of parameter descriptions for Z3 `simplify` procedure."""
9134 return ParamDescrsRef(Z3_simplify_get_param_descrs(main_ctx().ref()), main_ctx())
9135
9136
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 9364 of file z3py.py.

9364def solve(*args, **keywords):
9365 """Solve the constraints `*args`.
9366
9367 This is a simple function for creating demonstrations. It creates a solver,
9368 configure it using the options in `keywords`, adds the constraints
9369 in `args`, and invokes check.
9370
9371 >>> a = Int('a')
9372 >>> solve(a > 0, a < 2)
9373 [a = 1]
9374 """
9375 show = keywords.pop("show", False)
9376 s = Solver()
9377 s.set(**keywords)
9378 s.add(*args)
9379 if show:
9380 print(s)
9381 r = s.check()
9382 if r == unsat:
9383 print("no solution")
9384 elif r == unknown:
9385 print("failed to solve")
9386 try:
9387 print(s.model())
9388 except Z3Exception:
9389 return
9390 else:
9391 print(s.model())
9392
9393

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

9394def solve_using(s, *args, **keywords):
9395 """Solve the constraints `*args` using solver `s`.
9396
9397 This is a simple function for creating demonstrations. It is similar to `solve`,
9398 but it uses the given solver `s`.
9399 It configures solver `s` using the options in `keywords`, adds the constraints
9400 in `args`, and invokes check.
9401 """
9402 show = keywords.pop("show", False)
9403 if z3_debug():
9404 _z3_assert(isinstance(s, Solver), "Solver object expected")
9405 s.set(**keywords)
9406 s.add(*args)
9407 if show:
9408 print("Problem:")
9409 print(s)
9410 r = s.check()
9411 if r == unsat:
9412 print("no solution")
9413 elif r == unknown:
9414 print("failed to solve")
9415 try:
9416 print(s.model())
9417 except Z3Exception:
9418 return
9419 else:
9420 if show:
9421 print("Solution:")
9422 print(s.model())
9423
9424

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

7656def SolverFor(logic, ctx=None, logFile=None):
7657 """Create a solver customized for the given logic.
7658
7659 The parameter `logic` is a string. It should be contains
7660 the name of a SMT-LIB logic.
7661 See http://www.smtlib.org/ for the name of all available logics.
7662
7663 >>> s = SolverFor("QF_LIA")
7664 >>> x = Int('x')
7665 >>> s.add(x > 0)
7666 >>> s.add(x < 2)
7667 >>> s.check()
7668 sat
7669 >>> s.model()
7670 [x = 1]
7671 """
7672 ctx = _get_ctx(ctx)
7673 logic = to_symbol(logic)
7674 return Solver(Z3_mk_solver_for_logic(ctx.ref(), logic), ctx, logFile)
7675
7676
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 3561 of file z3py.py.

3561def Sqrt(a, ctx=None):
3562 """ Return a Z3 expression which represents the square root of a.
3563
3564 >>> x = Real('x')
3565 >>> Sqrt(x)
3566 x**(1/2)
3567 """
3568 if not is_expr(a):
3569 ctx = _get_ctx(ctx)
3570 a = RealVal(a, ctx)
3571 return a ** "1/2"
3572
3573

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

4456def SRem(a, b):
4457 """Create the Z3 expression signed remainder.
4458
4459 Use the operator % for signed modulus, and URem() for unsigned remainder.
4460
4461 >>> x = BitVec('x', 32)
4462 >>> y = BitVec('y', 32)
4463 >>> SRem(x, y)
4464 SRem(x, y)
4465 >>> SRem(x, y).sort()
4466 BitVec(32)
4467 >>> (x % y).sexpr()
4468 '(bvsmod x y)'
4469 >>> SRem(x, y).sexpr()
4470 '(bvsrem x y)'
4471 """
4472 _check_bv_args(a, b)
4473 a, b = _coerce_exprs(a, b)
4474 return BitVecRef(Z3_mk_bvsrem(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4475
4476
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 11647 of file z3py.py.

11647def Star(re):
11648 """Create the regular expression accepting zero or more repetitions of argument.
11649 >>> re = Star(Re("a"))
11650 >>> print(simplify(InRe("aa", re)))
11651 True
11652 >>> print(simplify(InRe("ab", re)))
11653 False
11654 >>> print(simplify(InRe("", re)))
11655 True
11656 """
11657 if z3_debug():
11658 _z3_assert(is_expr(re), "expression expected")
11659 return ReRef(Z3_mk_re_star(re.ctx_ref(), re.as_ast()), re.ctx)
11660
11661
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 4968 of file z3py.py.

4968def Store(a, *args):
4969 """Return a Z3 store array expression.
4970
4971 >>> a = Array('a', IntSort(), IntSort())
4972 >>> i, v = Ints('i v')
4973 >>> s = Store(a, i, v)
4974 >>> s.sort()
4975 Array(Int, Int)
4976 >>> prove(s[i] == v)
4977 proved
4978 >>> j = Int('j')
4979 >>> prove(Implies(i != j, s[j] == a[j]))
4980 proved
4981 """
4982 return Update(a, args)
4983
4984

Referenced by ModelRef.get_interp().

◆ StrFromCode()

StrFromCode (   c)
Convert code to a string

Definition at line 11515 of file z3py.py.

11515def StrFromCode(c):
11516 """Convert code to a string"""
11517 if not is_expr(c):
11518 c = _py2expr(c)
11519 return SeqRef(Z3_mk_string_from_code(c.ctx_ref(), c.as_ast()), c.ctx)
11520
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 11272 of file z3py.py.

11272def String(name, ctx=None):
11273 """Return a string constant named `name`. If `ctx=None`, then the global context is used.
11274
11275 >>> x = String('x')
11276 """
11277 ctx = _get_ctx(ctx)
11278 return SeqRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), StringSort(ctx).ast), ctx)
11279
11280

◆ Strings()

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

Definition at line 11281 of file z3py.py.

11281def Strings(names, ctx=None):
11282 """Return a tuple of String constants. """
11283 ctx = _get_ctx(ctx)
11284 if isinstance(names, str):
11285 names = names.split(" ")
11286 return [String(name, ctx) for name in names]
11287
11288

◆ StringSort()

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

Definition at line 11087 of file z3py.py.

11087def StringSort(ctx=None):
11088 """Create a string sort
11089 >>> s = StringSort()
11090 >>> print(s)
11091 String
11092 """
11093 ctx = _get_ctx(ctx)
11094 return SeqSortRef(Z3_mk_string_sort(ctx.ref()), ctx)
11095

◆ StringVal()

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

Definition at line 11265 of file z3py.py.

11265def StringVal(s, ctx=None):
11266 """create a string expression"""
11267 s = "".join(str(ch) if 32 <= ord(ch) and ord(ch) < 127 else "\\u{%x}" % (ord(ch)) for ch in s)
11268 ctx = _get_ctx(ctx)
11269 return SeqRef(Z3_mk_string(ctx.ref(), s), ctx)
11270
11271
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 11509 of file z3py.py.

11509def StrToCode(s):
11510 """Convert a unit length string to integer code"""
11511 if not is_expr(s):
11512 s = _py2expr(s)
11513 return ArithRef(Z3_mk_string_to_code(s.ctx_ref(), s.as_ast()), s.ctx)
11514
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 11486 of file z3py.py.

11486def StrToInt(s):
11487 """Convert string expression to integer
11488 >>> a = StrToInt("1")
11489 >>> simplify(1 == a)
11490 True
11491 >>> b = StrToInt("2")
11492 >>> simplify(1 == b)
11493 False
11494 >>> c = StrToInt(IntToStr(2))
11495 >>> simplify(1 == c)
11496 False
11497 """
11498 s = _coerce_seq(s)
11499 return ArithRef(Z3_mk_str_to_int(s.ctx_ref(), s.as_ast()), s.ctx)
11500
11501
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 11303 of file z3py.py.

11303def SubSeq(s, offset, length):
11304 """Extract substring or subsequence starting at offset.
11305
11306 This is a convenience function that redirects to Extract(s, offset, length).
11307
11308 >>> s = StringVal("hello world")
11309 >>> SubSeq(s, 0, 5) # Extract "hello"
11310 str.substr("hello world", 0, 5)
11311 >>> simplify(SubSeq(StringVal("testing"), 2, 4))
11312 "stin"
11313 """
11314 return Extract(s, offset, length)
11315
11316

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

9137def substitute(t, *m):
9138 """Apply substitution m on t, m is a list of pairs of the form (from, to).
9139 Every occurrence in t of from is replaced with to.
9140
9141 >>> x = Int('x')
9142 >>> y = Int('y')
9143 >>> substitute(x + 1, (x, y + 1))
9144 y + 1 + 1
9145 >>> f = Function('f', IntSort(), IntSort())
9146 >>> substitute(f(x) + f(y), (f(x), IntVal(1)), (f(y), IntVal(1)))
9147 1 + 1
9148 """
9149 if isinstance(m, tuple):
9150 m1 = _get_args(m)
9151 if isinstance(m1, list) and all(isinstance(p, tuple) for p in m1):
9152 m = m1
9153 if z3_debug():
9154 _z3_assert(is_expr(t), "Z3 expression expected")
9155 _z3_assert(
9156 all([isinstance(p, tuple) and is_expr(p[0]) and is_expr(p[1]) for p in m]),
9157 "Z3 invalid substitution, expression pairs expected.")
9158 _z3_assert(
9159 all([p[0].sort().eq(p[1].sort()) for p in m]),
9160 'Z3 invalid substitution, mismatching "from" and "to" sorts.')
9161 num = len(m)
9162 _from = (Ast * num)()
9163 _to = (Ast * num)()
9164 for i in range(num):
9165 _from[i] = m[i][0].as_ast()
9166 _to[i] = m[i][1].as_ast()
9167 return _to_expr_ref(Z3_substitute(t.ctx.ref(), t.as_ast(), num, _from, _to), t.ctx)
9168
9169
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 9190 of file z3py.py.

9190def substitute_funs(t, *m):
9191 """Apply substitution m on t, m is a list of pairs of a function and expression (from, to)
9192 Every occurrence in to of the function from is replaced with the expression to.
9193 The expression to can have free variables, that refer to the arguments of from.
9194 For examples, see
9195 """
9196 if isinstance(m, tuple):
9197 m1 = _get_args(m)
9198 if isinstance(m1, list) and all(isinstance(p, tuple) for p in m1):
9199 m = m1
9200 if z3_debug():
9201 _z3_assert(is_expr(t), "Z3 expression expected")
9202 _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.")
9203 num = len(m)
9204 _from = (FuncDecl * num)()
9205 _to = (Ast * num)()
9206 for i in range(num):
9207 _from[i] = m[i][0].as_func_decl()
9208 _to[i] = m[i][1].as_ast()
9209 return _to_expr_ref(Z3_substitute_funs(t.ctx.ref(), t.as_ast(), num, _from, _to), t.ctx)
9210
9211
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 9170 of file z3py.py.

9170def substitute_vars(t, *m):
9171 """Substitute the free variables in t with the expression in m.
9172
9173 >>> v0 = Var(0, IntSort())
9174 >>> v1 = Var(1, IntSort())
9175 >>> x = Int('x')
9176 >>> f = Function('f', IntSort(), IntSort(), IntSort())
9177 >>> # replace v0 with x+1 and v1 with x
9178 >>> substitute_vars(f(v0, v1), x + 1, x)
9179 f(x + 1, x)
9180 """
9181 if z3_debug():
9182 _z3_assert(is_expr(t), "Z3 expression expected")
9183 _z3_assert(all([is_expr(n) for n in m]), "Z3 invalid substitution, list of expressions expected.")
9184 num = len(m)
9185 _to = (Ast * num)()
9186 for i in range(num):
9187 _to[i] = m[i].as_ast()
9188 return _to_expr_ref(Z3_substitute_vars(t.ctx.ref(), t.as_ast(), num, _to), t.ctx)
9189
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 11289 of file z3py.py.

11289def SubString(s, offset, length):
11290 """Extract substring or subsequence starting at offset.
11291
11292 This is a convenience function that redirects to Extract(s, offset, length).
11293
11294 >>> s = StringVal("hello world")
11295 >>> SubString(s, 6, 5) # Extract "world"
11296 str.substr("hello world", 6, 5)
11297 >>> simplify(SubString(StringVal("hello"), 1, 3))
11298 "ell"
11299 """
11300 return Extract(s, offset, length)
11301
11302

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

11372def SuffixOf(a, b):
11373 """Check if 'a' is a suffix of 'b'
11374 >>> s1 = SuffixOf("ab", "abc")
11375 >>> simplify(s1)
11376 False
11377 >>> s2 = SuffixOf("bc", "abc")
11378 >>> simplify(s2)
11379 True
11380 """
11381 ctx = _get_ctx2(a, b)
11382 a = _coerce_seq(a, ctx)
11383 b = _coerce_seq(b, ctx)
11384 return BoolRef(Z3_mk_seq_suffix(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
11385
11386
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 9212 of file z3py.py.

9212def Sum(*args):
9213 """Create the sum of the Z3 expressions.
9214
9215 >>> a, b, c = Ints('a b c')
9216 >>> Sum(a, b, c)
9217 a + b + c
9218 >>> Sum([a, b, c])
9219 a + b + c
9220 >>> A = IntVector('a', 5)
9221 >>> Sum(A)
9222 a__0 + a__1 + a__2 + a__3 + a__4
9223 """
9224 args = _get_args(args)
9225 if len(args) == 0:
9226 return 0
9227 ctx = _ctx_from_ast_arg_list(args)
9228 if ctx is None:
9229 return _reduce(lambda a, b: a + b, args, 0)
9230 args = _coerce_expr_list(args, ctx)
9231 if is_bv(args[0]):
9232 return _reduce(lambda a, b: a + b, args, 0)
9233 else:
9234 _args, sz = _to_ast_array(args)
9235 return ArithRef(Z3_mk_add(ctx.ref(), sz, _args), ctx)
9236
9237
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 8791 of file z3py.py.

8791def tactic_description(name, ctx=None):
8792 """Return a short description for the tactic named `name`.
8793
8794 >>> d = tactic_description('simplify')
8795 """
8796 ctx = _get_ctx(ctx)
8797 return Z3_tactic_get_descr(ctx.ref(), name)
8798
8799
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 8780 of file z3py.py.

8780def tactics(ctx=None):
8781 """Return a list of all available tactics in Z3.
8782
8783 >>> l = tactics()
8784 >>> l.count('simplify') == 1
8785 True
8786 """
8787 ctx = _get_ctx(ctx)
8788 return [Z3_get_tactic_name(ctx.ref(), i) for i in range(Z3_get_num_tactics(ctx.ref()))]
8789
8790
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 8648 of file z3py.py.

8648def Then(*ts, **ks):
8649 """Return a tactic that applies the tactics in `*ts` in sequence. Shorthand for AndThen(*ts, **ks).
8650
8651 >>> x, y = Ints('x y')
8652 >>> t = Then(Tactic('simplify'), Tactic('solve-eqs'))
8653 >>> t(And(x == 0, y > x + 1))
8654 [[Not(y <= 1)]]
8655 >>> t(And(x == 0, y > x + 1)).as_expr()
8656 Not(y <= 1)
8657 """
8658 return AndThen(*ts, **ks)
8659
8660

◆ to_Ast()

to_Ast (   ptr)

Definition at line 11731 of file z3py.py.

11731def to_Ast(ptr,):
11732 ast = Ast(ptr)
11733 super(ctypes.c_void_p, ast).__init__(ptr)
11734 return ast
11735

◆ to_AstVectorObj()

to_AstVectorObj (   ptr)

Definition at line 11741 of file z3py.py.

11741def to_AstVectorObj(ptr,):
11742 v = AstVectorObj(ptr)
11743 super(ctypes.c_void_p, v).__init__(ptr)
11744 return v
11745
11746# NB. my-hacky-class only works for a single instance of OnClause
11747# it should be replaced with a proper correlation between OnClause
11748# and object references that can be passed over the FFI.
11749# for UserPropagator we use a global dictionary, which isn't great code.
11750

◆ to_ContextObj()

to_ContextObj (   ptr)

Definition at line 11736 of file z3py.py.

11736def to_ContextObj(ptr,):
11737 ctx = ContextObj(ptr)
11738 super(ctypes.c_void_p, ctx).__init__(ptr)
11739 return ctx
11740

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

3526def ToInt(a):
3527 """ Return the Z3 expression ToInt(a).
3528
3529 >>> x = Real('x')
3530 >>> x.sort()
3531 Real
3532 >>> n = ToInt(x)
3533 >>> n
3534 ToInt(x)
3535 >>> n.sort()
3536 Int
3537 """
3538 if z3_debug():
3539 _z3_assert(a.is_real(), "Z3 real expression expected.")
3540 ctx = a.ctx
3541 return ArithRef(Z3_mk_real2int(ctx.ref(), a.as_ast()), ctx)
3542
3543
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 3506 of file z3py.py.

3506def ToReal(a):
3507 """ Return the Z3 expression ToReal(a).
3508
3509 >>> x = Int('x')
3510 >>> x.sort()
3511 Int
3512 >>> n = ToReal(x)
3513 >>> n
3514 ToReal(x)
3515 >>> n.sort()
3516 Real
3517 """
3518 ctx = a.ctx
3519 if isinstance(a, BoolRef):
3520 return If(a, RealVal(1, ctx), RealVal(0, ctx))
3521 if z3_debug():
3522 _z3_assert(a.is_int(), "Z3 integer expression expected.")
3523 return ArithRef(Z3_mk_int2real(ctx.ref(), a.as_ast()), ctx)
3524
3525
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 11724 of file z3py.py.

11724def TransitiveClosure(f):
11725 """Given a binary relation R, such that the two arguments have the same sort
11726 create the transitive closure relation R+.
11727 The transitive closure R+ is a new relation.
11728 """
11729 return FuncDeclRef(Z3_mk_transitive_closure(f.ctx_ref(), f.ast), f.ctx)
11730
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 11716 of file z3py.py.

11716def TreeOrder(a, index):
11717 return FuncDeclRef(Z3_mk_tree_order(a.ctx_ref(), a.ast, index), a.ctx)
11718
11719
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 8771 of file z3py.py.

8771def TryFor(t, ms, ctx=None):
8772 """Return a tactic that applies `t` to a given goal for `ms` milliseconds.
8773
8774 If `t` does not terminate in `ms` milliseconds, then it fails.
8775 """
8776 t = _to_tactic(t, ctx)
8777 return Tactic(Z3_tactic_try_for(t.ctx.ref(), t.tactic, ms), t.ctx)
8778
8779
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 5554 of file z3py.py.

5554def TupleSort(name, sorts, ctx=None):
5555 """Create a named tuple sort base on a set of underlying sorts
5556 Example:
5557 >>> pair, mk_pair, (first, second) = TupleSort("pair", [IntSort(), StringSort()])
5558 """
5559 tuple = Datatype(name, ctx)
5560 projects = [("project%d" % i, sorts[i]) for i in range(len(sorts))]
5561 tuple.declare(name, *projects)
5562 tuple = tuple.create()
5563 return tuple, tuple.constructor(0), [tuple.accessor(0, i) for i in range(len(sorts))]
5564
5565

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

4414def UDiv(a, b):
4415 """Create the Z3 expression (unsigned) division `self / other`.
4416
4417 Use the operator / for signed division.
4418
4419 >>> x = BitVec('x', 32)
4420 >>> y = BitVec('y', 32)
4421 >>> UDiv(x, y)
4422 UDiv(x, y)
4423 >>> UDiv(x, y).sort()
4424 BitVec(32)
4425 >>> (x / y).sexpr()
4426 '(bvsdiv x y)'
4427 >>> UDiv(x, y).sexpr()
4428 '(bvudiv x y)'
4429 """
4430 _check_bv_args(a, b)
4431 a, b = _coerce_exprs(a, b)
4432 return BitVecRef(Z3_mk_bvudiv(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4433
4434
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 4378 of file z3py.py.

4378def UGE(a, b):
4379 """Create the Z3 expression (unsigned) `other >= self`.
4380
4381 Use the operator >= for signed greater than or equal to.
4382
4383 >>> x, y = BitVecs('x y', 32)
4384 >>> UGE(x, y)
4385 UGE(x, y)
4386 >>> (x >= y).sexpr()
4387 '(bvsge x y)'
4388 >>> UGE(x, y).sexpr()
4389 '(bvuge x y)'
4390 """
4391 _check_bv_args(a, b)
4392 a, b = _coerce_exprs(a, b)
4393 return BoolRef(Z3_mk_bvuge(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4394
4395
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 4396 of file z3py.py.

4396def UGT(a, b):
4397 """Create the Z3 expression (unsigned) `other > self`.
4398
4399 Use the operator > for signed greater than.
4400
4401 >>> x, y = BitVecs('x y', 32)
4402 >>> UGT(x, y)
4403 UGT(x, y)
4404 >>> (x > y).sexpr()
4405 '(bvsgt x y)'
4406 >>> UGT(x, y).sexpr()
4407 '(bvugt x y)'
4408 """
4409 _check_bv_args(a, b)
4410 a, b = _coerce_exprs(a, b)
4411 return BoolRef(Z3_mk_bvugt(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4412
4413
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 4342 of file z3py.py.

4342def ULE(a, b):
4343 """Create the Z3 expression (unsigned) `other <= self`.
4344
4345 Use the operator <= for signed less than or equal to.
4346
4347 >>> x, y = BitVecs('x y', 32)
4348 >>> ULE(x, y)
4349 ULE(x, y)
4350 >>> (x <= y).sexpr()
4351 '(bvsle x y)'
4352 >>> ULE(x, y).sexpr()
4353 '(bvule x y)'
4354 """
4355 _check_bv_args(a, b)
4356 a, b = _coerce_exprs(a, b)
4357 return BoolRef(Z3_mk_bvule(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4358
4359
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 4360 of file z3py.py.

4360def ULT(a, b):
4361 """Create the Z3 expression (unsigned) `other < self`.
4362
4363 Use the operator < for signed less than.
4364
4365 >>> x, y = BitVecs('x y', 32)
4366 >>> ULT(x, y)
4367 ULT(x, y)
4368 >>> (x < y).sexpr()
4369 '(bvslt x y)'
4370 >>> ULT(x, y).sexpr()
4371 '(bvult x y)'
4372 """
4373 _check_bv_args(a, b)
4374 a, b = _coerce_exprs(a, b)
4375 return BoolRef(Z3_mk_bvult(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4376
4377
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 11574 of file z3py.py.

11574def Union(*args):
11575 """Create union of regular expressions.
11576 >>> re = Union(Re("a"), Re("b"), Re("c"))
11577 >>> print (simplify(InRe("d", re)))
11578 False
11579 """
11580 args = _get_args(args)
11581 sz = len(args)
11582 if z3_debug():
11583 _z3_assert(sz > 0, "At least one argument expected.")
11584 _z3_assert(all([is_re(a) for a in args]), "All arguments must be regular expressions.")
11585 if sz == 1:
11586 return args[0]
11587 ctx = args[0].ctx
11588 v = (Ast * sz)()
11589 for i in range(sz):
11590 v[i] = args[i].as_ast()
11591 return ReRef(Z3_mk_re_union(ctx.ref(), sz, v), ctx)
11592
11593
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 11352 of file z3py.py.

11352def Unit(a):
11353 """Create a singleton sequence"""
11354 return SeqRef(Z3_mk_seq_unit(a.ctx_ref(), a.as_ast()), a.ctx)
11355
11356
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 4925 of file z3py.py.

4925def Update(a, *args):
4926 """Return a Z3 store array expression.
4927
4928 >>> a = Array('a', IntSort(), IntSort())
4929 >>> i, v = Ints('i v')
4930 >>> s = Update(a, i, v)
4931 >>> s.sort()
4932 Array(Int, Int)
4933 >>> prove(s[i] == v)
4934 proved
4935 >>> j = Int('j')
4936 >>> prove(Implies(i != j, s[j] == a[j]))
4937 proved
4938 """
4939 if z3_debug():
4940 _z3_assert(is_array_sort(a), "First argument must be a Z3 array expression")
4941 args = _get_args(args)
4942 ctx = a.ctx
4943 if len(args) <= 1:
4944 raise Z3Exception("array update requires index and value arguments")
4945 if len(args) == 2:
4946 i = args[0]
4947 v = args[1]
4948 i = a.sort().domain().cast(i)
4949 v = a.sort().range().cast(v)
4950 return _to_expr_ref(Z3_mk_store(ctx.ref(), a.as_ast(), i.as_ast(), v.as_ast()), ctx)
4951 v = a.sort().range().cast(args[-1])
4952 idxs = [a.sort().domain_n(i).cast(args[i]) for i in range(len(args)-1)]
4953 _args, sz = _to_ast_array(idxs)
4954 return _to_expr_ref(Z3_mk_store_n(ctx.ref(), a.as_ast(), sz, _args, v.as_ast()), ctx)
4955
4956
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 4435 of file z3py.py.

4435def URem(a, b):
4436 """Create the Z3 expression (unsigned) remainder `self % other`.
4437
4438 Use the operator % for signed modulus, and SRem() for signed remainder.
4439
4440 >>> x = BitVec('x', 32)
4441 >>> y = BitVec('y', 32)
4442 >>> URem(x, y)
4443 URem(x, y)
4444 >>> URem(x, y).sort()
4445 BitVec(32)
4446 >>> (x % y).sexpr()
4447 '(bvsmod x y)'
4448 >>> URem(x, y).sexpr()
4449 '(bvurem x y)'
4450 """
4451 _check_bv_args(a, b)
4452 a, b = _coerce_exprs(a, b)
4453 return BitVecRef(Z3_mk_bvurem(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4454
4455
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 11894 of file z3py.py.

11894def user_prop_binding(ctx, cb, q_ref, inst_ref):
11895 prop = _prop_closures.get(ctx)
11896 old_cb = prop.cb
11897 prop.cb = cb
11898 q = _to_expr_ref(to_Ast(q_ref), prop.ctx())
11899 inst = _to_expr_ref(to_Ast(inst_ref), prop.ctx())
11900 r = prop.binding(q, inst)
11901 prop.cb = old_cb
11902 return r
11903
11904

◆ user_prop_created()

user_prop_created (   ctx,
  cb,
  id 
)

Definition at line 11852 of file z3py.py.

11852def user_prop_created(ctx, cb, id):
11853 prop = _prop_closures.get(ctx)
11854 old_cb = prop.cb
11855 prop.cb = cb
11856 id = _to_expr_ref(to_Ast(id), prop.ctx())
11857 prop.created(id)
11858 prop.cb = old_cb
11859
11860

◆ user_prop_decide()

user_prop_decide (   ctx,
  cb,
  t_ref,
  idx,
  phase 
)

Definition at line 11886 of file z3py.py.

11886def user_prop_decide(ctx, cb, t_ref, idx, phase):
11887 prop = _prop_closures.get(ctx)
11888 old_cb = prop.cb
11889 prop.cb = cb
11890 t = _to_expr_ref(to_Ast(t_ref), prop.ctx())
11891 prop.decide(t, idx, phase)
11892 prop.cb = old_cb
11893

◆ user_prop_diseq()

user_prop_diseq (   ctx,
  cb,
  x,
  y 
)

Definition at line 11877 of file z3py.py.

11877def user_prop_diseq(ctx, cb, x, y):
11878 prop = _prop_closures.get(ctx)
11879 old_cb = prop.cb
11880 prop.cb = cb
11881 x = _to_expr_ref(to_Ast(x), prop.ctx())
11882 y = _to_expr_ref(to_Ast(y), prop.ctx())
11883 prop.diseq(x, y)
11884 prop.cb = old_cb
11885

◆ user_prop_eq()

user_prop_eq (   ctx,
  cb,
  x,
  y 
)

Definition at line 11868 of file z3py.py.

11868def user_prop_eq(ctx, cb, x, y):
11869 prop = _prop_closures.get(ctx)
11870 old_cb = prop.cb
11871 prop.cb = cb
11872 x = _to_expr_ref(to_Ast(x), prop.ctx())
11873 y = _to_expr_ref(to_Ast(y), prop.ctx())
11874 prop.eq(x, y)
11875 prop.cb = old_cb
11876

◆ user_prop_final()

user_prop_final (   ctx,
  cb 
)

Definition at line 11861 of file z3py.py.

11861def user_prop_final(ctx, cb):
11862 prop = _prop_closures.get(ctx)
11863 old_cb = prop.cb
11864 prop.cb = cb
11865 prop.final()
11866 prop.cb = old_cb
11867

◆ user_prop_fixed()

user_prop_fixed (   ctx,
  cb,
  id,
  value 
)

Definition at line 11843 of file z3py.py.

11843def user_prop_fixed(ctx, cb, id, value):
11844 prop = _prop_closures.get(ctx)
11845 old_cb = prop.cb
11846 prop.cb = cb
11847 id = _to_expr_ref(to_Ast(id), prop.ctx())
11848 value = _to_expr_ref(to_Ast(value), prop.ctx())
11849 prop.fixed(id, value)
11850 prop.cb = old_cb
11851

◆ user_prop_fresh()

user_prop_fresh (   ctx,
  _new_ctx 
)

Definition at line 11829 of file z3py.py.

11829def user_prop_fresh(ctx, _new_ctx):
11830 _prop_closures.set_threaded()
11831 prop = _prop_closures.get(ctx)
11832 nctx = Context()
11833 Z3_del_context(nctx.ctx)
11834 new_ctx = to_ContextObj(_new_ctx)
11835 nctx.ctx = new_ctx
11836 nctx.eh = Z3_set_error_handler(new_ctx, z3_error_handler)
11837 nctx.owner = False
11838 new_prop = prop.fresh(nctx)
11839 _prop_closures.set(new_prop.id, new_prop)
11840 return new_prop.id
11841
11842
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 11823 of file z3py.py.

11823def user_prop_pop(ctx, cb, num_scopes):
11824 prop = _prop_closures.get(ctx)
11825 prop.cb = cb
11826 prop.pop(num_scopes)
11827
11828

◆ user_prop_push()

user_prop_push (   ctx,
  cb 
)

Definition at line 11817 of file z3py.py.

11817def user_prop_push(ctx, cb):
11818 prop = _prop_closures.get(ctx)
11819 prop.cb = cb
11820 prop.push()
11821
11822

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

1578def Var(idx : int, s : SortRef) -> ExprRef:
1579 """Create a Z3 free variable. Free variables are used to create quantified formulas.
1580 A free variable with index n is bound when it occurs within the scope of n+1 quantified
1581 declarations.
1582
1583 >>> Var(0, IntSort())
1584 Var(0)
1585 >>> eq(Var(0, IntSort()), Var(0, BoolSort()))
1586 False
1587 """
1588 if z3_debug():
1589 _z3_assert(is_sort(s), "Z3 sort expected")
1590 return _to_expr_ref(Z3_mk_bound(s.ctx_ref(), idx, s.ast), s.ctx)
1591
1592
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 9065 of file z3py.py.

9065def When(p, t, ctx=None):
9066 """Return a tactic that applies tactic `t` only if probe `p` evaluates to true.
9067 Otherwise, it returns the input goal unmodified.
9068
9069 >>> t = When(Probe('size') > 2, Tactic('simplify'))
9070 >>> x, y = Ints('x y')
9071 >>> g = Goal()
9072 >>> g.add(x > 0)
9073 >>> g.add(y > 0)
9074 >>> t(g)
9075 [[x > 0, y > 0]]
9076 >>> g.add(x == y + 1)
9077 >>> t(g)
9078 [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
9079 """
9080 p = _to_probe(p, ctx)
9081 t = _to_tactic(t, ctx)
9082 return Tactic(Z3_tactic_when(t.ctx.ref(), p.probe, t.tactic), t.ctx)
9083
9084
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 8722 of file z3py.py.

8722def With(t, *args, **keys):
8723 """Return a tactic that applies tactic `t` using the given configuration options.
8724
8725 >>> x, y = Ints('x y')
8726 >>> t = With(Tactic('simplify'), som=True)
8727 >>> t((x + 1)*(y + 2) == 0)
8728 [[2*x + y + x*y == -2]]
8729 """
8730 ctx = keys.pop("ctx", None)
8731 t = _to_tactic(t, ctx)
8732 p = args2params(args, keys, t.ctx)
8733 return Tactic(Z3_tactic_using_params(t.ctx.ref(), t.tactic, p.params), t.ctx)
8734
8735
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 8736 of file z3py.py.

8736def WithParams(t, p):
8737 """Return a tactic that applies tactic `t` using the given configuration options.
8738
8739 >>> x, y = Ints('x y')
8740 >>> p = ParamsRef()
8741 >>> p.set("som", True)
8742 >>> t = WithParams(Tactic('simplify'), p)
8743 >>> t((x + 1)*(y + 2) == 0)
8744 [[2*x + y + x*y == -2]]
8745 """
8746 t = _to_tactic(t, None)
8747 return Tactic(Z3_tactic_using_params(t.ctx.ref(), t.tactic, p.params), t.ctx)
8748
8749

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

1935def Xor(a, b, ctx=None):
1936 """Create a Z3 Xor expression.
1937
1938 >>> p, q = Bools('p q')
1939 >>> Xor(p, q)
1940 Xor(p, q)
1941 >>> simplify(Xor(p, q))
1942 Not(p == q)
1943 """
1944 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1945 s = BoolSort(ctx)
1946 a = s.cast(a)
1947 b = s.cast(b)
1948 return BoolRef(Z3_mk_xor(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
1949
1950
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 4571 of file z3py.py.

4571def ZeroExt(n, a):
4572 """Return a bit-vector expression with `n` extra zero-bits.
4573
4574 >>> x = BitVec('x', 16)
4575 >>> n = ZeroExt(8, x)
4576 >>> n.size()
4577 24
4578 >>> n
4579 ZeroExt(8, x)
4580 >>> n.sort()
4581 BitVec(24)
4582 >>> v0 = BitVecVal(2, 2)
4583 >>> v0
4584 2
4585 >>> v0.size()
4586 2
4587 >>> v = simplify(ZeroExt(6, v0))
4588 >>> v
4589 2
4590 >>> v.size()
4591 8
4592 """
4593 if z3_debug():
4594 _z3_assert(_is_int(n), "First argument must be an integer")
4595 _z3_assert(is_bv(a), "Second argument must be a Z3 bit-vector expression")
4596 return BitVecRef(Z3_mk_zero_ext(a.ctx_ref(), n, a.as_ast()), a.ctx)
4597
4598
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 9617 of file z3py.py.

◆ _dflt_fpsort_sbits

int _dflt_fpsort_sbits = 53
protected

Definition at line 9618 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 9616 of file z3py.py.

◆ _main_ctx

_main_ctx = None
protected

Definition at line 266 of file z3py.py.

◆ _my_hacky_class

_my_hacky_class = None
protected

Definition at line 11751 of file z3py.py.

◆ _on_clause_eh

_on_clause_eh = Z3_on_clause_eh(on_clause_eh)
protected

Definition at line 11759 of file z3py.py.

◆ _on_model_eh

_on_model_eh = on_model_eh_type(_global_on_model)
protected

Definition at line 8121 of file z3py.py.

◆ _on_models

dict _on_models = {}
protected

Definition at line 8113 of file z3py.py.

◆ _prop_closures

_prop_closures = None
protected

Definition at line 11808 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 9636 of file z3py.py.

◆ _user_prop_binding

_user_prop_binding = Z3_on_binding_eh(user_prop_binding)
protected

Definition at line 11914 of file z3py.py.

◆ _user_prop_created

_user_prop_created = Z3_created_eh(user_prop_created)
protected

Definition at line 11909 of file z3py.py.

◆ _user_prop_decide

_user_prop_decide = Z3_decide_eh(user_prop_decide)
protected

Definition at line 11913 of file z3py.py.

◆ _user_prop_diseq

_user_prop_diseq = Z3_eq_eh(user_prop_diseq)
protected

Definition at line 11912 of file z3py.py.

◆ _user_prop_eq

_user_prop_eq = Z3_eq_eh(user_prop_eq)
protected

Definition at line 11911 of file z3py.py.

◆ _user_prop_final

_user_prop_final = Z3_final_eh(user_prop_final)
protected

Definition at line 11910 of file z3py.py.

◆ _user_prop_fixed

_user_prop_fixed = Z3_fixed_eh(user_prop_fixed)
protected

Definition at line 11908 of file z3py.py.

◆ _user_prop_fresh

_user_prop_fresh = Z3_fresh_eh(user_prop_fresh)
protected

Definition at line 11907 of file z3py.py.

◆ _user_prop_pop

_user_prop_pop = Z3_pop_eh(user_prop_pop)
protected

Definition at line 11906 of file z3py.py.

◆ _user_prop_push

_user_prop_push = Z3_push_eh(user_prop_push)
protected

Definition at line 11905 of file z3py.py.

◆ sat

Definition at line 7110 of file z3py.py.

◆ unknown

Definition at line 7112 of file z3py.py.

◆ unsat

Definition at line 7111 of file z3py.py.

◆ Z3_DEBUG

Z3_DEBUG = __debug__

Definition at line 67 of file z3py.py.