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

8684def _and_then(t1, t2, ctx=None):
8685 t1 = _to_tactic(t1, ctx)
8686 t2 = _to_tactic(t2, ctx)
8687 if z3_debug():
8688 _z3_assert(t1.ctx == t2.ctx, "Context mismatch")
8689 return Tactic(Z3_tactic_and_then(t1.ctx.ref(), t1.tactic, t2.tactic), t1.ctx)
8690
8691
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 4788 of file z3py.py.

4788def _array_select(ar, arg):
4789 if isinstance(arg, tuple):
4790 args = [ar.sort().domain_n(i).cast(arg[i]) for i in range(len(arg))]
4791 _args, sz = _to_ast_array(args)
4792 return _to_expr_ref(Z3_mk_select_n(ar.ctx_ref(), ar.as_ast(), sz, _args), ar.ctx)
4793 arg = ar.sort().domain().cast(arg)
4794 return _to_expr_ref(Z3_mk_select(ar.ctx_ref(), ar.as_ast(), arg.as_ast()), ar.ctx)
4795
4796
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 522 of file z3py.py.

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

4349def _check_bv_args(a, b):
4350 if z3_debug():
4351 _z3_assert(is_bv(a) or is_bv(b), "First or second argument must be a Z3 bit-vector expression")
4352
4353

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

10796def _check_fp_args(a, b):
10797 if z3_debug():
10798 _z3_assert(is_fp(a) or is_fp(b), "First or second argument must be a Z3 floating-point expression")
10799
10800

◆ _check_same_sort()

_check_same_sort (   a,
  b,
  ctx = None 
)
protected

Definition at line 1289 of file z3py.py.

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

11239def _coerce_char(ch, ctx=None):
11240 if isinstance(ch, str):
11241 ctx = _get_ctx(ctx)
11242 ch = CharVal(ch, ctx)
11243 if not is_expr(ch):
11244 raise Z3Exception("Character expression expected")
11245 return ch
11246

◆ _coerce_expr_list()

_coerce_expr_list (   alist,
  ctx = None 
)
protected

Definition at line 1333 of file z3py.py.

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

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

◆ _coerce_expr_merge()

_coerce_expr_merge (   s,
  a 
)
protected

Definition at line 1271 of file z3py.py.

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

Referenced by _coerce_exprs().

◆ _coerce_exprs()

_coerce_exprs (   a,
  b,
  ctx = None 
)
protected

Definition at line 1302 of file z3py.py.

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

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

9745def _coerce_fp_expr_list(alist, ctx):
9746 first_fp_sort = None
9747 for a in alist:
9748 if is_fp(a):
9749 if first_fp_sort is None:
9750 first_fp_sort = a.sort()
9751 elif first_fp_sort == a.sort():
9752 pass # OK, same as before
9753 else:
9754 # we saw at least 2 different float sorts; something will
9755 # throw a sort mismatch later, for now assume None.
9756 first_fp_sort = None
9757 break
9758
9759 r = []
9760 for i in range(len(alist)):
9761 a = alist[i]
9762 is_repr = isinstance(a, str) and a.contains("2**(") and a.endswith(")")
9763 if is_repr or _is_int(a) or isinstance(a, (float, bool)):
9764 r.append(FPVal(a, None, first_fp_sort, ctx))
9765 else:
9766 r.append(a)
9767 return _coerce_expr_list(r, ctx)
9768
9769
9770# FP Sorts
9771

◆ _coerce_seq()

_coerce_seq (   s,
  ctx = None 
)
protected

Definition at line 11289 of file z3py.py.

11289def _coerce_seq(s, ctx=None):
11290 if isinstance(s, str):
11291 ctx = _get_ctx(ctx)
11292 s = StringVal(s, ctx)
11293 if not is_expr(s):
11294 raise Z3Exception("Non-expression passed as a sequence")
11295 if not is_seq(s):
11296 raise Z3Exception("Non-sequence passed as a sequence")
11297 return s
11298
11299

Referenced by Concat().

◆ _ctx_from_ast_arg_list()

_ctx_from_ast_arg_list (   args,
  default_ctx = None 
)
protected

Definition at line 528 of file z3py.py.

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

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

542def _ctx_from_ast_args(*args):
543 return _ctx_from_ast_arg_list(args)
544
545

◆ _dflt_fps()

_dflt_fps (   ctx = None)
protected

Definition at line 9741 of file z3py.py.

9741def _dflt_fps(ctx=None):
9742 return get_default_fp_sort(ctx)
9743
9744

◆ _dflt_rm()

_dflt_rm (   ctx = None)
protected

Definition at line 9737 of file z3py.py.

9737def _dflt_rm(ctx=None):
9738 return get_default_rounding_mode(ctx)
9739
9740

◆ _dict2darray()

_dict2darray (   decls,
  ctx 
)
protected

Definition at line 9610 of file z3py.py.

9610def _dict2darray(decls, ctx):
9611 sz = len(decls)
9612 _names = (Symbol * sz)()
9613 _decls = (FuncDecl * sz)()
9614 i = 0
9615 for k in decls:
9616 v = decls[k]
9617 if z3_debug():
9618 _z3_assert(isinstance(k, str), "String expected")
9619 _z3_assert(is_func_decl(v) or is_const(v), "Z3 declaration or constant expected")
9620 _names[i] = to_symbol(k, ctx)
9621 if is_const(v):
9622 _decls[i] = v.decl().ast
9623 else:
9624 _decls[i] = v.ast
9625 i = i + 1
9626 return sz, _names, _decls
9627

◆ _dict2sarray()

_dict2sarray (   sorts,
  ctx 
)
protected

Definition at line 9594 of file z3py.py.

9594def _dict2sarray(sorts, ctx):
9595 sz = len(sorts)
9596 _names = (Symbol * sz)()
9597 _sorts = (Sort * sz)()
9598 i = 0
9599 for k in sorts:
9600 v = sorts[k]
9601 if z3_debug():
9602 _z3_assert(isinstance(k, str), "String expected")
9603 _z3_assert(is_sort(v), "Z3 sort expected")
9604 _names[i] = to_symbol(k, ctx)
9605 _sorts[i] = v.ast
9606 i = i + 1
9607 return sz, _names, _sorts
9608
9609

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

287def _get_ctx(ctx) -> Context:
288 if ctx is None:
289 return main_ctx()
290 else:
291 return ctx
292
293

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

11300def _get_ctx2(a, b, ctx=None):
11301 if is_expr(a):
11302 return a.ctx
11303 if is_expr(b):
11304 return b.ctx
11305 if ctx is None:
11306 ctx = main_ctx()
11307 return ctx
11308
11309

◆ _global_on_model()

_global_on_model (   ctx)
protected

Definition at line 8186 of file z3py.py.

8186def _global_on_model(ctx):
8187 (fn, mdl) = _on_models[ctx]
8188 fn(mdl)
8189
8190

◆ _has_probe()

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

Definition at line 1974 of file z3py.py.

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

Referenced by And(), and Or().

◆ _is_algebraic()

_is_algebraic (   ctx,
  a 
)
protected

Definition at line 2882 of file z3py.py.

2882def _is_algebraic(ctx, a):
2883 return Z3_is_algebraic_number(ctx.ref(), a)
2884
2885
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 2878 of file z3py.py.

2878def _is_numeral(ctx, a):
2879 return Z3_is_numeral_ast(ctx.ref(), a)
2880
2881
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 1531 of file z3py.py.

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

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

10584def _mk_fp_bin(f, rm, a, b, ctx):
10585 ctx = _get_ctx(ctx)
10586 [a, b] = _coerce_fp_expr_list([a, b], ctx)
10587 if z3_debug():
10588 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
10589 _z3_assert(is_fp(a) or is_fp(b), "Second or third argument must be a Z3 floating-point expression")
10590 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast()), ctx)
10591
10592

◆ _mk_fp_bin_norm()

_mk_fp_bin_norm (   f,
  a,
  b,
  ctx 
)
protected

Definition at line 10593 of file z3py.py.

10593def _mk_fp_bin_norm(f, a, b, ctx):
10594 ctx = _get_ctx(ctx)
10595 [a, b] = _coerce_fp_expr_list([a, b], ctx)
10596 if z3_debug():
10597 _z3_assert(is_fp(a) or is_fp(b), "First or second argument must be a Z3 floating-point expression")
10598 return FPRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
10599
10600

◆ _mk_fp_bin_pred()

_mk_fp_bin_pred (   f,
  a,
  b,
  ctx 
)
protected

Definition at line 10601 of file z3py.py.

10601def _mk_fp_bin_pred(f, a, b, ctx):
10602 ctx = _get_ctx(ctx)
10603 [a, b] = _coerce_fp_expr_list([a, b], ctx)
10604 if z3_debug():
10605 _z3_assert(is_fp(a) or is_fp(b), "First or second argument must be a Z3 floating-point expression")
10606 return BoolRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
10607
10608

◆ _mk_fp_tern()

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

Definition at line 10609 of file z3py.py.

10609def _mk_fp_tern(f, rm, a, b, c, ctx):
10610 ctx = _get_ctx(ctx)
10611 [a, b, c] = _coerce_fp_expr_list([a, b, c], ctx)
10612 if z3_debug():
10613 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
10614 _z3_assert(is_fp(a) or is_fp(b) or is_fp(
10615 c), "Second, third or fourth argument must be a Z3 floating-point expression")
10616 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
10617
10618

◆ _mk_fp_unary()

_mk_fp_unary (   f,
  rm,
  a,
  ctx 
)
protected

Definition at line 10567 of file z3py.py.

10567def _mk_fp_unary(f, rm, a, ctx):
10568 ctx = _get_ctx(ctx)
10569 [a] = _coerce_fp_expr_list([a], ctx)
10570 if z3_debug():
10571 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
10572 _z3_assert(is_fp(a), "Second argument must be a Z3 floating-point expression")
10573 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast()), ctx)
10574
10575

◆ _mk_fp_unary_pred()

_mk_fp_unary_pred (   f,
  a,
  ctx 
)
protected

Definition at line 10576 of file z3py.py.

10576def _mk_fp_unary_pred(f, a, ctx):
10577 ctx = _get_ctx(ctx)
10578 [a] = _coerce_fp_expr_list([a], ctx)
10579 if z3_debug():
10580 _z3_assert(is_fp(a), "First argument must be a Z3 floating-point expression")
10581 return BoolRef(f(ctx.ref(), a.as_ast()), ctx)
10582
10583

◆ _mk_quantifier()

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

Definition at line 2330 of file z3py.py.

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

8692def _or_else(t1, t2, ctx=None):
8693 t1 = _to_tactic(t1, ctx)
8694 t2 = _to_tactic(t2, ctx)
8695 if z3_debug():
8696 _z3_assert(t1.ctx == t2.ctx, "Context mismatch")
8697 return Tactic(Z3_tactic_or_else(t1.ctx.ref(), t1.tactic, t2.tactic), t1.ctx)
8698
8699
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 9383 of file z3py.py.

9383def _pb_args_coeffs(args, default_ctx=None):
9384 args = _get_args_ast_list(args)
9385 if len(args) == 0:
9386 return _get_ctx(default_ctx), 0, (Ast * 0)(), (ctypes.c_int * 0)()
9387 args = [_reorder_pb_arg(arg) for arg in args]
9388 args, coeffs = zip(*args)
9389 if z3_debug():
9390 _z3_assert(len(args) > 0, "Non empty list of arguments expected")
9391 ctx = _ctx_from_ast_arg_list(args)
9392 if z3_debug():
9393 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
9394 args = _coerce_expr_list(args, ctx)
9395 _args, sz = _to_ast_array(args)
9396 _coeffs = (ctypes.c_int * len(coeffs))()
9397 for i in range(len(coeffs)):
9398 _z3_check_cint_overflow(coeffs[i], "coefficient")
9399 _coeffs[i] = coeffs[i]
9400 return ctx, sz, _args, _coeffs, args
9401
9402

◆ _probe_and()

_probe_and (   args,
  ctx 
)
protected

Definition at line 9107 of file z3py.py.

9107def _probe_and(args, ctx):
9108 return _probe_nary(Z3_probe_and, args, ctx)
9109
9110

Referenced by And().

◆ _probe_nary()

_probe_nary (   f,
  args,
  ctx 
)
protected

Definition at line 9097 of file z3py.py.

9097def _probe_nary(f, args, ctx):
9098 if z3_debug():
9099 _z3_assert(len(args) > 0, "At least one argument expected")
9100 num = len(args)
9101 r = _to_probe(args[0], ctx)
9102 for i in range(num - 1):
9103 r = Probe(f(ctx.ref(), r.probe, _to_probe(args[i + 1], ctx).probe), ctx)
9104 return r
9105
9106

◆ _probe_or()

_probe_or (   args,
  ctx 
)
protected

Definition at line 9111 of file z3py.py.

9111def _probe_or(args, ctx):
9112 return _probe_nary(Z3_probe_or, args, ctx)
9113
9114

Referenced by Or().

◆ _prove_html()

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

Definition at line 9574 of file z3py.py.

9574def _prove_html(claim, show=False, **keywords):
9575 """Version of function `prove` that renders HTML."""
9576 if z3_debug():
9577 _z3_assert(is_bool(claim), "Z3 Boolean expression expected")
9578 s = Solver()
9579 s.set(**keywords)
9580 s.add(Not(claim))
9581 if show:
9582 print(s)
9583 r = s.check()
9584 if r == unsat:
9585 print("<b>proved</b>")
9586 elif r == unknown:
9587 print("<b>failed to prove</b>")
9588 print(s.model())
9589 else:
9590 print("<b>counterexample</b>")
9591 print(s.model())
9592
9593

◆ _py2expr()

_py2expr (   a,
  ctx = None 
)
protected

Definition at line 3283 of file z3py.py.

3283def _py2expr(a, ctx=None):
3284 if isinstance(a, bool):
3285 return BoolVal(a, ctx)
3286 if _is_int(a):
3287 return IntVal(a, ctx)
3288 if isinstance(a, float):
3289 return RealVal(a, ctx)
3290 if isinstance(a, str):
3291 return StringVal(a, ctx)
3292 if is_expr(a):
3293 return a
3294 if z3_debug():
3295 _z3_assert(False, "Python bool, int, long or float expected")
3296
3297

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

◆ _reduce()

_reduce (   func,
  sequence,
  initial 
)
protected

Definition at line 1326 of file z3py.py.

1326def _reduce(func, sequence, initial):
1327 result = initial
1328 for element in sequence:
1329 result = func(result, element)
1330 return result
1331
1332

Referenced by _coerce_expr_list().

◆ _reorder_pb_arg()

_reorder_pb_arg (   arg)
protected

Definition at line 9376 of file z3py.py.

9376def _reorder_pb_arg(arg):
9377 a, b = arg
9378 if not _is_int(b) and _is_int(a):
9379 return b, a
9380 return arg
9381
9382

◆ _solve_html()

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

Definition at line 9525 of file z3py.py.

9525def _solve_html(*args, **keywords):
9526 """Version of function `solve` that renders HTML output."""
9527 show = keywords.pop("show", False)
9528 s = Solver()
9529 s.set(**keywords)
9530 s.add(*args)
9531 if show:
9532 print("<b>Problem:</b>")
9533 print(s)
9534 r = s.check()
9535 if r == unsat:
9536 print("<b>no solution</b>")
9537 elif r == unknown:
9538 print("<b>failed to solve</b>")
9539 try:
9540 print(s.model())
9541 except Z3Exception:
9542 return
9543 else:
9544 if show:
9545 print("<b>Solution:</b>")
9546 print(s.model())
9547
9548

◆ _solve_using_html()

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

Definition at line 9549 of file z3py.py.

9549def _solve_using_html(s, *args, **keywords):
9550 """Version of function `solve_using` that renders HTML."""
9551 show = keywords.pop("show", False)
9552 if z3_debug():
9553 _z3_assert(isinstance(s, Solver), "Solver object expected")
9554 s.set(**keywords)
9555 s.add(*args)
9556 if show:
9557 print("<b>Problem:</b>")
9558 print(s)
9559 r = s.check()
9560 if r == unsat:
9561 print("<b>no solution</b>")
9562 elif r == unknown:
9563 print("<b>failed to solve</b>")
9564 try:
9565 print(s.model())
9566 except Z3Exception:
9567 return
9568 else:
9569 if show:
9570 print("<b>Solution:</b>")
9571 print(s.model())
9572
9573

◆ _sort()

SortRef _sort ( Context  ctx,
Any  a 
)
protected

Definition at line 726 of file z3py.py.

726def _sort(ctx : Context, a : Any) -> SortRef:
727 return _to_sort_ref(Z3_get_sort(ctx.ref(), a), ctx)
728
729

◆ _sort_kind()

_sort_kind (   ctx,
  s 
)
protected

Sorts.

Definition at line 586 of file z3py.py.

586def _sort_kind(ctx, s):
587 return Z3_get_sort_kind(ctx.ref(), s)
588
589
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 554 of file z3py.py.

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

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

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

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

◆ _to_expr_ref()

_to_expr_ref (   a,
  ctx 
)
protected

Definition at line 1221 of file z3py.py.

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

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

◆ _to_float_str()

_to_float_str (   val,
  exp = 0 
)
protected

Definition at line 10329 of file z3py.py.

10329def _to_float_str(val, exp=0):
10330 if isinstance(val, float):
10331 if math.isnan(val):
10332 res = "NaN"
10333 elif val == 0.0:
10334 sone = math.copysign(1.0, val)
10335 if sone < 0.0:
10336 return "-0.0"
10337 else:
10338 return "+0.0"
10339 elif val == float("+inf"):
10340 res = "+oo"
10341 elif val == float("-inf"):
10342 res = "-oo"
10343 else:
10344 v = val.as_integer_ratio()
10345 num = v[0]
10346 den = v[1]
10347 rvs = str(num) + "/" + str(den)
10348 res = rvs + "p" + _to_int_str(exp)
10349 elif isinstance(val, bool):
10350 if val:
10351 res = "1.0"
10352 else:
10353 res = "0.0"
10354 elif _is_int(val):
10355 res = str(val)
10356 elif isinstance(val, str):
10357 inx = val.find("*(2**")
10358 if inx == -1:
10359 res = val
10360 elif val[-1] == ")":
10361 res = val[0:inx]
10362 exp = str(int(val[inx + 5:-1]) + int(exp))
10363 else:
10364 _z3_assert(False, "String does not have floating-point numeral form.")
10365 elif z3_debug():
10366 _z3_assert(False, "Python value cannot be used to create floating-point numerals.")
10367 if exp == 0:
10368 return res
10369 else:
10370 return res + "p" + exp
10371
10372

◆ _to_func_decl_array()

_to_func_decl_array (   args)
protected

Definition at line 546 of file z3py.py.

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

◆ _to_func_decl_ref()

_to_func_decl_ref (   a,
  ctx 
)
protected

Definition at line 962 of file z3py.py.

962def _to_func_decl_ref(a, ctx):
963 return FuncDeclRef(a, ctx)
964
965

Referenced by _to_ast_ref().

◆ _to_goal()

_to_goal (   a)
protected

Definition at line 8668 of file z3py.py.

8668def _to_goal(a):
8669 if isinstance(a, BoolRef):
8670 goal = Goal(ctx=a.ctx)
8671 goal.add(a)
8672 return goal
8673 else:
8674 return a
8675
8676

◆ _to_int_str()

_to_int_str (   val)
protected

Definition at line 3332 of file z3py.py.

3332def _to_int_str(val):
3333 if isinstance(val, float):
3334 return str(int(val))
3335 elif isinstance(val, bool):
3336 if val:
3337 return "1"
3338 else:
3339 return "0"
3340 else:
3341 return str(val)
3342
3343

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

2108def _to_pattern(arg):
2109 if is_pattern(arg):
2110 return arg
2111 else:
2112 return MultiPattern(arg)
2113

Referenced by _mk_quantifier().

◆ _to_probe()

_to_probe (   p,
  ctx = None 
)
protected

Definition at line 9051 of file z3py.py.

9051def _to_probe(p, ctx=None):
9052 if is_probe(p):
9053 return p
9054 else:
9055 return Probe(p, ctx)
9056
9057

◆ _to_ref_array()

_to_ref_array (   ref,
  args 
)
protected

Definition at line 562 of file z3py.py.

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

◆ _to_sort_ref()

_to_sort_ref (   s,
  ctx 
)
protected

Definition at line 695 of file z3py.py.

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

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

8677def _to_tactic(t, ctx=None):
8678 if isinstance(t, Tactic):
8679 return t
8680 else:
8681 return Tactic(t, ctx)
8682
8683

◆ _valid_accessor()

_valid_accessor (   acc)
protected

Datatypes.

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

Definition at line 5220 of file z3py.py.

5220def _valid_accessor(acc):
5221 """Return `True` if acc is pair of the form (String, Datatype or Sort). """
5222 if not isinstance(acc, tuple):
5223 return False
5224 if len(acc) != 2:
5225 return False
5226 return isinstance(acc[0], str) and (isinstance(acc[1], Datatype) or is_sort(acc[1]))
5227
5228

Referenced by Datatype.declare_core().

◆ _z3_assert()

_z3_assert (   cond,
  msg 
)
protected

Definition at line 113 of file z3py.py.

113def _z3_assert(cond, msg):
114 if not cond:
115 raise Z3Exception(msg)
116
117

Referenced by QuantifierRef.__getitem__(), ModelRef.__getitem__(), Context.__init__(), ParamDescrsRef.__init__(), Goal.__init__(), ArithRef.__mod__(), ArithRef.__rmod__(), _check_bv_args(), _coerce_expr_merge(), _ctx_from_ast_arg_list(), _mk_bin(), _mk_quantifier(), _py2expr(), _to_sort_ref(), _z3_check_cint_overflow(), DatatypeSortRef.accessor(), And(), ExprRef.arg(), args2params(), ArraySort(), IntNumRef.as_long(), RatNumRef.as_long(), Solver.assert_and_track(), BV2Int(), BVRedAnd(), BVRedOr(), BVSNegNoOverflow(), SortRef.cast(), Concat(), Const(), DatatypeSortRef.constructor(), Goal.convert_model(), CreateDatatypes(), ExprRef.decl(), Datatype.declare(), Datatype.declare_core(), Default(), Distinct(), EnumSort(), eq(), AstRef.eq(), Ext(), Extract(), FreshConst(), FreshFunction(), Function(), get_as_array_func(), ModelRef.get_interp(), get_map_func(), ModelRef.get_universe(), get_var_index(), If(), IsInt(), K(), ExprRef.kind(), Map(), MultiPattern(), QuantifierRef.no_pattern(), ExprRef.num_args(), Or(), QuantifierRef.pattern(), RatVal(), RecFunction(), DatatypeSortRef.recognizer(), RepeatBitVec(), Select(), ParamsRef.set(), set_param(), SignExt(), ToInt(), ToReal(), AstRef.translate(), Goal.translate(), ModelRef.translate(), Update(), ExprRef.update(), DatatypeRef.update_field(), ParamsRef.validate(), Var(), QuantifierRef.var_name(), QuantifierRef.var_sort(), and ZeroExt().

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

9335def Abs(arg):
9336 """Create the absolute value of an arithmetic expression"""
9337 return If(arg > 0, arg, -arg)
9338
9339

Referenced by ArithRef.__abs__().

◆ AllChar()

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

Definition at line 11772 of file z3py.py.

11772def AllChar(regex_sort, ctx=None):
11773 """Create a regular expression that accepts all single character strings
11774 """
11775 return ReRef(Z3_mk_re_allchar(regex_sort.ctx_ref(), regex_sort.ast), regex_sort.ctx)
11776
11777# Special Relations
11778
11779
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 1982 of file z3py.py.

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

8700def AndThen(*ts, **ks):
8701 """Return a tactic that applies the tactics in `*ts` in sequence.
8702
8703 >>> x, y = Ints('x y')
8704 >>> t = AndThen(Tactic('simplify'), Tactic('solve-eqs'))
8705 >>> t(And(x == 0, y > x + 1))
8706 [[Not(y <= 1)]]
8707 >>> t(And(x == 0, y > x + 1)).as_expr()
8708 Not(y <= 1)
8709 """
8710 if z3_debug():
8711 _z3_assert(len(ts) >= 2, "At least two arguments expected")
8712 ctx = ks.get("ctx", None)
8713 num = len(ts)
8714 r = ts[0]
8715 for i in range(num - 1):
8716 r = _and_then(r, ts[i + 1], ctx)
8717 return r
8718
8719

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

5695def args2params(arguments, keywords, ctx=None):
5696 """Convert python arguments into a Z3_params object.
5697 A ':' is added to the keywords, and '_' is replaced with '-'
5698
5699 >>> args2params(['model', True, 'relevancy', 2], {'elim_and' : True})
5700 (params model true relevancy 2 elim_and true)
5701 """
5702 if z3_debug():
5703 _z3_assert(len(arguments) % 2 == 0, "Argument list must have an even number of elements.")
5704 prev = None
5705 r = ParamsRef(ctx)
5706 for a in arguments:
5707 if prev is None:
5708 prev = a
5709 else:
5710 r.set(prev, a)
5711 prev = None
5712 for k in keywords:
5713 v = keywords[k]
5714 r.set(k, v)
5715 return r
5716
5717

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

4923def Array(name, *sorts):
4924 """Return an array constant named `name` with the given domain and range sorts.
4925
4926 >>> a = Array('a', IntSort(), IntSort())
4927 >>> a.sort()
4928 Array(Int, Int)
4929 >>> a[0]
4930 a[0]
4931 """
4932 s = ArraySort(sorts)
4933 ctx = s.ctx
4934 return ArrayRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), s.ast), ctx)
4935
4936
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 4890 of file z3py.py.

4890def ArraySort(*sig):
4891 """Return the Z3 array sort with the given domain and range sorts.
4892
4893 >>> A = ArraySort(IntSort(), BoolSort())
4894 >>> A
4895 Array(Int, Bool)
4896 >>> A.domain()
4897 Int
4898 >>> A.range()
4899 Bool
4900 >>> AA = ArraySort(IntSort(), A)
4901 >>> AA
4902 Array(Int, Array(Int, Bool))
4903 """
4904 sig = _get_args(sig)
4905 if z3_debug():
4906 _z3_assert(len(sig) > 1, "At least two arguments expected")
4907 arity = len(sig) - 1
4908 r = sig[arity]
4909 d = sig[0]
4910 if z3_debug():
4911 for s in sig:
4912 _z3_assert(is_sort(s), "Z3 sort expected")
4913 _z3_assert(s.ctx == r.ctx, "Context mismatch")
4914 ctx = d.ctx
4915 if len(sig) == 2:
4916 return ArraySortRef(Z3_mk_array_sort(ctx.ref(), d.ast, r.ast), ctx)
4917 dom = (Sort * arity)()
4918 for i in range(arity):
4919 dom[i] = sig[i].ast
4920 return ArraySortRef(Z3_mk_array_sort_n(ctx.ref(), arity, dom, r.ast), ctx)
4921
4922
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 9358 of file z3py.py.

9358def AtLeast(*args):
9359 """Create an at-least Pseudo-Boolean k constraint.
9360
9361 >>> a, b, c = Bools('a b c')
9362 >>> f = AtLeast(a, b, c, 2)
9363 """
9364 args = _get_args(args)
9365 if z3_debug():
9366 _z3_assert(len(args) > 1, "Non empty list of arguments expected")
9367 ctx = _ctx_from_ast_arg_list(args)
9368 if z3_debug():
9369 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
9370 args1 = _coerce_expr_list(args[:-1], ctx)
9371 k = args[-1]
9372 _args, sz = _to_ast_array(args1)
9373 return BoolRef(Z3_mk_atleast(ctx.ref(), sz, _args, k), ctx)
9374
9375
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 9340 of file z3py.py.

9340def AtMost(*args):
9341 """Create an at-most Pseudo-Boolean k constraint.
9342
9343 >>> a, b, c = Bools('a b c')
9344 >>> f = AtMost(a, b, c, 2)
9345 """
9346 args = _get_args(args)
9347 if z3_debug():
9348 _z3_assert(len(args) > 1, "Non empty list of arguments expected")
9349 ctx = _ctx_from_ast_arg_list(args)
9350 if z3_debug():
9351 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
9352 args1 = _coerce_expr_list(args[:-1], ctx)
9353 k = args[-1]
9354 _args, sz = _to_ast_array(args1)
9355 return BoolRef(Z3_mk_atmost(ctx.ref(), sz, _args, k), ctx)
9356
9357
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 4204 of file z3py.py.

4204def BitVec(name, bv, ctx=None):
4205 """Return a bit-vector constant named `name`. `bv` may be the number of bits of a bit-vector sort.
4206 If `ctx=None`, then the global context is used.
4207
4208 >>> x = BitVec('x', 16)
4209 >>> is_bv(x)
4210 True
4211 >>> x.size()
4212 16
4213 >>> x.sort()
4214 BitVec(16)
4215 >>> word = BitVecSort(16)
4216 >>> x2 = BitVec('x', word)
4217 >>> eq(x, x2)
4218 True
4219 """
4220 if isinstance(bv, BitVecSortRef):
4221 ctx = bv.ctx
4222 else:
4223 ctx = _get_ctx(ctx)
4224 bv = BitVecSort(bv, ctx)
4225 return BitVecRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), bv.ast), ctx)
4226
4227

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

4228def BitVecs(names, bv, ctx=None):
4229 """Return a tuple of bit-vector constants of size bv.
4230
4231 >>> x, y, z = BitVecs('x y z', 16)
4232 >>> x.size()
4233 16
4234 >>> x.sort()
4235 BitVec(16)
4236 >>> Sum(x, y, z)
4237 0 + x + y + z
4238 >>> Product(x, y, z)
4239 1*x*y*z
4240 >>> simplify(Product(x, y, z))
4241 x*y*z
4242 """
4243 ctx = _get_ctx(ctx)
4244 if isinstance(names, str):
4245 names = names.split(" ")
4246 return [BitVec(name, bv, ctx) for name in names]
4247
4248

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

4172def BitVecSort(sz, ctx=None):
4173 """Return a Z3 bit-vector sort of the given size. If `ctx=None`, then the global context is used.
4174
4175 >>> Byte = BitVecSort(8)
4176 >>> Word = BitVecSort(16)
4177 >>> Byte
4178 BitVec(8)
4179 >>> x = Const('x', Byte)
4180 >>> eq(x, BitVec('x', 8))
4181 True
4182 """
4183 ctx = _get_ctx(ctx)
4184 return BitVecSortRef(Z3_mk_bv_sort(ctx.ref(), sz), ctx)
4185
4186
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 4187 of file z3py.py.

4187def BitVecVal(val, bv, ctx=None):
4188 """Return a bit-vector value with the given number of bits. If `ctx=None`, then the global context is used.
4189
4190 >>> v = BitVecVal(10, 32)
4191 >>> v
4192 10
4193 >>> print("0x%.8x" % v.as_long())
4194 0x0000000a
4195 """
4196 if is_bv_sort(bv):
4197 ctx = bv.ctx
4198 return BitVecNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), bv.ast), ctx)
4199 else:
4200 ctx = _get_ctx(ctx)
4201 return BitVecNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), BitVecSort(bv, ctx).ast), ctx)
4202
4203
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 1861 of file z3py.py.

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

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

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

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

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

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

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

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

4140def BV2Int(a, is_signed=False):
4141 """Return the Z3 expression BV2Int(a).
4142
4143 >>> b = BitVec('b', 3)
4144 >>> BV2Int(b).sort()
4145 Int
4146 >>> x = Int('x')
4147 >>> x > BV2Int(b)
4148 x > BV2Int(b)
4149 >>> x > BV2Int(b, is_signed=False)
4150 x > BV2Int(b)
4151 >>> x > BV2Int(b, is_signed=True)
4152 x > If(b < 0, BV2Int(b) - 8, BV2Int(b))
4153 >>> solve(x > BV2Int(b), b == 1, x < 3)
4154 [x = 2, b = 1]
4155 """
4156 if z3_debug():
4157 _z3_assert(is_bv(a), "First argument must be a Z3 bit-vector expression")
4158 ctx = a.ctx
4159 # investigate problem with bv2int
4160 return ArithRef(Z3_mk_bv2int(ctx.ref(), a.as_ast(), is_signed), ctx)
4161
4162
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 4649 of file z3py.py.

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

4656def BVAddNoUnderflow(a, b):
4657 """A predicate the determines that signed bit-vector addition does not underflow"""
4658 _check_bv_args(a, b)
4659 a, b = _coerce_exprs(a, b)
4660 return BoolRef(Z3_mk_bvadd_no_underflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4661
4662
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 4691 of file z3py.py.

4691def BVMulNoOverflow(a, b, signed):
4692 """A predicate the determines that bit-vector multiplication does not overflow"""
4693 _check_bv_args(a, b)
4694 a, b = _coerce_exprs(a, b)
4695 return BoolRef(Z3_mk_bvmul_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast(), signed), a.ctx)
4696
4697
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 4698 of file z3py.py.

4698def BVMulNoUnderflow(a, b):
4699 """A predicate the determines that bit-vector signed multiplication does not underflow"""
4700 _check_bv_args(a, b)
4701 a, b = _coerce_exprs(a, b)
4702 return BoolRef(Z3_mk_bvmul_no_underflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4703
4704
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 4635 of file z3py.py.

4635def BVRedAnd(a):
4636 """Return the reduction-and expression of `a`."""
4637 if z3_debug():
4638 _z3_assert(is_bv(a), "First argument must be a Z3 bit-vector expression")
4639 return BitVecRef(Z3_mk_bvredand(a.ctx_ref(), a.as_ast()), a.ctx)
4640
4641
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 4642 of file z3py.py.

4642def BVRedOr(a):
4643 """Return the reduction-or expression of `a`."""
4644 if z3_debug():
4645 _z3_assert(is_bv(a), "First argument must be a Z3 bit-vector expression")
4646 return BitVecRef(Z3_mk_bvredor(a.ctx_ref(), a.as_ast()), a.ctx)
4647
4648
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 4677 of file z3py.py.

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

4684def BVSNegNoOverflow(a):
4685 """A predicate the determines that bit-vector unary negation does not overflow"""
4686 if z3_debug():
4687 _z3_assert(is_bv(a), "First argument must be a Z3 bit-vector expression")
4688 return BoolRef(Z3_mk_bvneg_no_overflow(a.ctx_ref(), a.as_ast()), a.ctx)
4689
4690
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 4663 of file z3py.py.

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

4670def BVSubNoUnderflow(a, b, signed):
4671 """A predicate the determines that bit-vector subtraction does not underflow"""
4672 _check_bv_args(a, b)
4673 a, b = _coerce_exprs(a, b)
4674 return BoolRef(Z3_mk_bvsub_no_underflow(a.ctx_ref(), a.as_ast(), b.as_ast(), signed), a.ctx)
4675
4676
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 3586 of file z3py.py.

3586def Cbrt(a, ctx=None):
3587 """ Return a Z3 expression which represents the cubic root of a.
3588
3589 >>> x = Real('x')
3590 >>> Cbrt(x)
3591 x**(1/3)
3592 """
3593 if not is_expr(a):
3594 ctx = _get_ctx(ctx)
3595 a = RealVal(a, ctx)
3596 return a ** "1/3"
3597

◆ CharFromBv()

CharFromBv (   bv)

Definition at line 11272 of file z3py.py.

11272def CharFromBv(bv):
11273 if not is_expr(bv):
11274 raise Z3Exception("Bit-vector expression needed")
11275 return _to_expr_ref(Z3_mk_char_from_bv(bv.ctx_ref(), bv.as_ast()), bv.ctx)
11276
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 11285 of file z3py.py.

11285def CharIsDigit(ch, ctx=None):
11286 ch = _coerce_char(ch, ctx)
11287 return ch.is_digit()
11288

◆ CharSort()

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

Definition at line 11168 of file z3py.py.

11168def CharSort(ctx=None):
11169 """Create a character sort
11170 >>> ch = CharSort()
11171 >>> print(ch)
11172 Char
11173 """
11174 ctx = _get_ctx(ctx)
11175 return CharSortRef(Z3_mk_char_sort(ctx.ref()), ctx)
11176
11177
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 11277 of file z3py.py.

11277def CharToBv(ch, ctx=None):
11278 ch = _coerce_char(ch, ctx)
11279 return ch.to_bv()
11280

◆ CharToInt()

CharToInt (   ch,
  ctx = None 
)

Definition at line 11281 of file z3py.py.

11281def CharToInt(ch, ctx=None):
11282 ch = _coerce_char(ch, ctx)
11283 return ch.to_int()
11284

◆ CharVal()

CharVal (   ch,
  ctx = None 
)

Definition at line 11264 of file z3py.py.

11264def CharVal(ch, ctx=None):
11265 ctx = _get_ctx(ctx)
11266 if isinstance(ch, str):
11267 ch = ord(ch)
11268 if not isinstance(ch, int):
11269 raise Z3Exception("character value should be an ordinal")
11270 return _to_expr_ref(Z3_mk_char(ctx.ref(), ch), ctx)
11271
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 11714 of file z3py.py.

11714def Complement(re):
11715 """Create the complement regular expression."""
11716 return ReRef(Z3_mk_re_complement(re.ctx_ref(), re.as_ast()), re.ctx)
11717
11718
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 4249 of file z3py.py.

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

9157def Cond(p, t1, t2, ctx=None):
9158 """Return a tactic that applies tactic `t1` to a goal if probe `p` evaluates to true, and `t2` otherwise.
9159
9160 >>> t = Cond(Probe('is-qfnra'), Tactic('qfnra'), Tactic('smt'))
9161 """
9162 p = _to_probe(p, ctx)
9163 t1 = _to_tactic(t1, ctx)
9164 t2 = _to_tactic(t2, ctx)
9165 return Tactic(Z3_tactic_cond(t1.ctx.ref(), p.probe, t1.tactic, t2.tactic), t1.ctx)
9166
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 1540 of file z3py.py.

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

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

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

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

11459def Contains(a, b):
11460 """Check if 'a' contains 'b'
11461 >>> s1 = Contains("abc", "ab")
11462 >>> simplify(s1)
11463 True
11464 >>> s2 = Contains("abc", "bc")
11465 >>> simplify(s2)
11466 True
11467 >>> x, y, z = Strings('x y z')
11468 >>> s3 = Contains(Concat(x,y,z), y)
11469 >>> simplify(s3)
11470 True
11471 """
11472 ctx = _get_ctx2(a, b)
11473 a = _coerce_seq(a, ctx)
11474 b = _coerce_seq(b, ctx)
11475 return BoolRef(Z3_mk_seq_contains(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
11476
11477
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 5341 of file z3py.py.

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

5567def DatatypeSort(name, params=None, ctx=None):
5568 """Create a reference to a sort that was declared, or will be declared, as a recursive datatype.
5569
5570 Args:
5571 name: name of the datatype sort
5572 params: optional list/tuple of sort parameters for parametric datatypes
5573 ctx: Z3 context (optional)
5574
5575 Example:
5576 >>> # Non-parametric datatype
5577 >>> TreeRef = DatatypeSort('Tree')
5578 >>> # Parametric datatype with one parameter
5579 >>> ListIntRef = DatatypeSort('List', [IntSort()])
5580 >>> # Parametric datatype with multiple parameters
5581 >>> PairRef = DatatypeSort('Pair', [IntSort(), BoolSort()])
5582 """
5583 ctx = _get_ctx(ctx)
5584 if params is None or len(params) == 0:
5585 return DatatypeSortRef(Z3_mk_datatype_sort(ctx.ref(), to_symbol(name, ctx), 0, (Sort * 0)()), ctx)
5586 else:
5587 _params = (Sort * len(params))()
5588 for i in range(len(params)):
5589 _params[i] = params[i].ast
5590 return DatatypeSortRef(Z3_mk_datatype_sort(ctx.ref(), to_symbol(name, ctx), len(params), _params), ctx)
5591
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 730 of file z3py.py.

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

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

4969def Default(a):
4970 """ Return a default value for array expression.
4971 >>> b = K(IntSort(), 1)
4972 >>> prove(Default(b) == 1)
4973 proved
4974 """
4975 if z3_debug():
4976 _z3_assert(is_array_sort(a), "First argument must be a Z3 array expression")
4977 return a.default()
4978
4979

◆ describe_probes()

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

Definition at line 9078 of file z3py.py.

9078def describe_probes():
9079 """Display a (tabular) description of all available probes in Z3."""
9080 if in_html_mode():
9081 even = True
9082 print('<table border="1" cellpadding="2" cellspacing="0">')
9083 for p in probes():
9084 if even:
9085 print('<tr style="background-color:#CFCFCF">')
9086 even = False
9087 else:
9088 print("<tr>")
9089 even = True
9090 print("<td>%s</td><td>%s</td></tr>" % (p, insert_line_breaks(probe_description(p), 40)))
9091 print("</table>")
9092 else:
9093 for p in probes():
9094 print("%s : %s" % (p, probe_description(p)))
9095
9096

◆ describe_tactics()

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

Definition at line 8872 of file z3py.py.

8872def describe_tactics():
8873 """Display a (tabular) description of all available tactics in Z3."""
8874 if in_html_mode():
8875 even = True
8876 print('<table border="1" cellpadding="2" cellspacing="0">')
8877 for t in tactics():
8878 if even:
8879 print('<tr style="background-color:#CFCFCF">')
8880 even = False
8881 else:
8882 print("<tr>")
8883 even = True
8884 print("<td>%s</td><td>%s</td></tr>" % (t, insert_line_breaks(tactic_description(t), 40)))
8885 print("</table>")
8886 else:
8887 for t in tactics():
8888 print("%s : %s" % (t, tactic_description(t)))
8889
8890

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

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

◆ Diff()

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

Definition at line 11764 of file z3py.py.

11764def Diff(a, b, ctx=None):
11765 """Create the difference regular expression
11766 """
11767 if z3_debug():
11768 _z3_assert(is_expr(a), "expression expected")
11769 _z3_assert(is_expr(b), "expression expected")
11770 return ReRef(Z3_mk_re_diff(a.ctx_ref(), a.ast, b.ast), a.ctx)
11771
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 5604 of file z3py.py.

5604def DisjointSum(name, sorts, ctx=None):
5605 """Create a named tagged union sort base on a set of underlying sorts
5606 Example:
5607 >>> sum, ((inject0, extract0), (inject1, extract1)) = DisjointSum("+", [IntSort(), StringSort()])
5608 """
5609 sum = Datatype(name, ctx)
5610 for i in range(len(sorts)):
5611 sum.declare("inject%d" % i, ("project%d" % i, sorts[i]))
5612 sum = sum.create()
5613 return sum, [(sum.constructor(i), sum.accessor(i, 0)) for i in range(len(sorts))]
5614
5615

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

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

11389def Empty(s):
11390 """Create the empty sequence of the given sort
11391 >>> e = Empty(StringSort())
11392 >>> e2 = StringVal("")
11393 >>> print(e.eq(e2))
11394 True
11395 >>> e3 = Empty(SeqSort(IntSort()))
11396 >>> print(e3)
11397 Empty(Seq(Int))
11398 >>> e4 = Empty(ReSort(SeqSort(IntSort())))
11399 >>> print(e4)
11400 Empty(ReSort(Seq(Int)))
11401 """
11402 if isinstance(s, SeqSortRef):
11403 return SeqRef(Z3_mk_seq_empty(s.ctx_ref(), s.ast), s.ctx)
11404 if isinstance(s, ReSortRef):
11405 return ReRef(Z3_mk_re_empty(s.ctx_ref(), s.ast), s.ctx)
11406 raise Z3Exception("Non-sequence, non-regular expression sort passed to Empty")
11407
11408
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 5105 of file z3py.py.

5105def EmptySet(s):
5106 """Create the empty set
5107 >>> EmptySet(IntSort())
5108 K(Int, False)
5109 """
5110 ctx = s.ctx
5111 return ArrayRef(Z3_mk_empty_set(ctx.ref(), s.ast), ctx)
5112
5113
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 11883 of file z3py.py.

11883def ensure_prop_closures():
11884 global _prop_closures
11885 if _prop_closures is None:
11886 _prop_closures = PropClosures()
11887
11888

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

5616def EnumSort(name, values, ctx=None):
5617 """Return a new enumeration sort named `name` containing the given values.
5618
5619 The result is a pair (sort, list of constants).
5620 Example:
5621 >>> Color, (red, green, blue) = EnumSort('Color', ['red', 'green', 'blue'])
5622 """
5623 if z3_debug():
5624 _z3_assert(isinstance(name, str), "Name must be a string")
5625 _z3_assert(all([isinstance(v, str) for v in values]), "Enumeration sort values must be strings")
5626 _z3_assert(len(values) > 0, "At least one value expected")
5627 ctx = _get_ctx(ctx)
5628 num = len(values)
5629 _val_names = (Symbol * num)()
5630 for i in range(num):
5631 _val_names[i] = to_symbol(values[i], ctx)
5632 _values = (FuncDecl * num)()
5633 _testers = (FuncDecl * num)()
5634 name = to_symbol(name, ctx)
5635 S = DatatypeSortRef(Z3_mk_enumeration_sort(ctx.ref(), name, num, _val_names, _values, _testers), ctx)
5636 V = []
5637 for i in range(num):
5638 V.append(FuncDeclRef(_values[i], ctx))
5639 V = [a() for a in V]
5640 return S, V
5641
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 503 of file z3py.py.

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

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

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

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

5058def Ext(a, b):
5059 """Return extensionality index for one-dimensional arrays.
5060 >> a, b = Consts('a b', SetSort(IntSort()))
5061 >> Ext(a, b)
5062 Ext(a, b)
5063 """
5064 ctx = a.ctx
5065 if z3_debug():
5066 _z3_assert(is_array_sort(a) and (is_array(b) or b.is_lambda()), "arguments must be arrays")
5067 return _to_expr_ref(Z3_mk_array_ext(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
5068
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 4295 of file z3py.py.

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

9115def FailIf(p, ctx=None):
9116 """Return a tactic that fails if the probe `p` evaluates to true.
9117 Otherwise, it returns the input goal unmodified.
9118
9119 In the following example, the tactic applies 'simplify' if and only if there are
9120 more than 2 constraints in the goal.
9121
9122 >>> t = OrElse(FailIf(Probe('size') > 2), Tactic('simplify'))
9123 >>> x, y = Ints('x y')
9124 >>> g = Goal()
9125 >>> g.add(x > 0)
9126 >>> g.add(y > 0)
9127 >>> t(g)
9128 [[x > 0, y > 0]]
9129 >>> g.add(x == y + 1)
9130 >>> t(g)
9131 [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
9132 """
9133 p = _to_probe(p, ctx)
9134 return Tactic(Z3_tactic_fail_if(p.ctx.ref(), p.probe), p.ctx)
9135
9136
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 8044 of file z3py.py.

8044def FiniteDomainSort(name, sz, ctx=None):
8045 """Create a named finite domain sort of a given size sz"""
8046 if not isinstance(name, Symbol):
8047 name = to_symbol(name)
8048 ctx = _get_ctx(ctx)
8049 return FiniteDomainSortRef(Z3_mk_finite_domain_sort(ctx.ref(), name, sz), ctx)
8050
8051
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 8114 of file z3py.py.

8114def FiniteDomainVal(val, sort, ctx=None):
8115 """Return a Z3 finite-domain value. If `ctx=None`, then the global context is used.
8116
8117 >>> s = FiniteDomainSort('S', 256)
8118 >>> FiniteDomainVal(255, s)
8119 255
8120 >>> FiniteDomainVal('100', s)
8121 100
8122 """
8123 if z3_debug():
8124 _z3_assert(is_finite_domain_sort(sort), "Expected finite-domain sort")
8125 ctx = sort.ctx
8126 return FiniteDomainNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), sort.ast), ctx)
8127
8128

◆ Float128()

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

Definition at line 9843 of file z3py.py.

9843def Float128(ctx=None):
9844 """Floating-point 128-bit (quadruple) sort."""
9845 ctx = _get_ctx(ctx)
9846 return FPSortRef(Z3_mk_fpa_sort_128(ctx.ref()), ctx)
9847
9848
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 9807 of file z3py.py.

9807def Float16(ctx=None):
9808 """Floating-point 16-bit (half) sort."""
9809 ctx = _get_ctx(ctx)
9810 return FPSortRef(Z3_mk_fpa_sort_16(ctx.ref()), ctx)
9811
9812
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 9819 of file z3py.py.

9819def Float32(ctx=None):
9820 """Floating-point 32-bit (single) sort."""
9821 ctx = _get_ctx(ctx)
9822 return FPSortRef(Z3_mk_fpa_sort_32(ctx.ref()), ctx)
9823
9824
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 9831 of file z3py.py.

9831def Float64(ctx=None):
9832 """Floating-point 64-bit (double) sort."""
9833 ctx = _get_ctx(ctx)
9834 return FPSortRef(Z3_mk_fpa_sort_64(ctx.ref()), ctx)
9835
9836
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 9837 of file z3py.py.

9837def FloatDouble(ctx=None):
9838 """Floating-point 64-bit (double) sort."""
9839 ctx = _get_ctx(ctx)
9840 return FPSortRef(Z3_mk_fpa_sort_double(ctx.ref()), ctx)
9841
9842
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 9813 of file z3py.py.

9813def FloatHalf(ctx=None):
9814 """Floating-point 16-bit (half) sort."""
9815 ctx = _get_ctx(ctx)
9816 return FPSortRef(Z3_mk_fpa_sort_half(ctx.ref()), ctx)
9817
9818
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 9849 of file z3py.py.

9849def FloatQuadruple(ctx=None):
9850 """Floating-point 128-bit (quadruple) sort."""
9851 ctx = _get_ctx(ctx)
9852 return FPSortRef(Z3_mk_fpa_sort_quadruple(ctx.ref()), ctx)
9853
9854
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 9825 of file z3py.py.

9825def FloatSingle(ctx=None):
9826 """Floating-point 32-bit (single) sort."""
9827 ctx = _get_ctx(ctx)
9828 return FPSortRef(Z3_mk_fpa_sort_single(ctx.ref()), ctx)
9829
9830
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 2365 of file z3py.py.

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

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

10485def FP(name, fpsort, ctx=None):
10486 """Return a floating-point constant named `name`.
10487 `fpsort` is the floating-point sort.
10488 If `ctx=None`, then the global context is used.
10489
10490 >>> x = FP('x', FPSort(8, 24))
10491 >>> is_fp(x)
10492 True
10493 >>> x.ebits()
10494 8
10495 >>> x.sort()
10496 FPSort(8, 24)
10497 >>> word = FPSort(8, 24)
10498 >>> x2 = FP('x', word)
10499 >>> eq(x, x2)
10500 True
10501 """
10502 if isinstance(fpsort, FPSortRef) and ctx is None:
10503 ctx = fpsort.ctx
10504 else:
10505 ctx = _get_ctx(ctx)
10506 return FPRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), fpsort.ast), ctx)
10507
10508

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

10528def fpAbs(a, ctx=None):
10529 """Create a Z3 floating-point absolute value expression.
10530
10531 >>> s = FPSort(8, 24)
10532 >>> rm = RNE()
10533 >>> x = FPVal(1.0, s)
10534 >>> fpAbs(x)
10535 fpAbs(1)
10536 >>> y = FPVal(-20.0, s)
10537 >>> y
10538 -1.25*(2**4)
10539 >>> fpAbs(y)
10540 fpAbs(-1.25*(2**4))
10541 >>> fpAbs(-1.25*(2**4))
10542 fpAbs(-1.25*(2**4))
10543 >>> fpAbs(x).sort()
10544 FPSort(8, 24)
10545 """
10546 ctx = _get_ctx(ctx)
10547 [a] = _coerce_fp_expr_list([a], ctx)
10548 return FPRef(Z3_mk_fpa_abs(ctx.ref(), a.as_ast()), ctx)
10549
10550
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 10619 of file z3py.py.

10619def fpAdd(rm, a, b, ctx=None):
10620 """Create a Z3 floating-point addition expression.
10621
10622 >>> s = FPSort(8, 24)
10623 >>> rm = RNE()
10624 >>> x = FP('x', s)
10625 >>> y = FP('y', s)
10626 >>> fpAdd(rm, x, y)
10627 x + y
10628 >>> fpAdd(RTZ(), x, y) # default rounding mode is RTZ
10629 fpAdd(RTZ(), x, y)
10630 >>> fpAdd(rm, x, y).sort()
10631 FPSort(8, 24)
10632 """
10633 return _mk_fp_bin(Z3_mk_fpa_add, rm, a, b, ctx)
10634
10635

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

10941def fpBVToFP(v, sort, ctx=None):
10942 """Create a Z3 floating-point conversion expression that represents the
10943 conversion from a bit-vector term to a floating-point term.
10944
10945 >>> x_bv = BitVecVal(0x3F800000, 32)
10946 >>> x_fp = fpBVToFP(x_bv, Float32())
10947 >>> x_fp
10948 fpToFP(1065353216)
10949 >>> simplify(x_fp)
10950 1
10951 """
10952 _z3_assert(is_bv(v), "First argument must be a Z3 bit-vector expression")
10953 _z3_assert(is_fp_sort(sort), "Second argument must be a Z3 floating-point sort.")
10954 ctx = _get_ctx(ctx)
10955 return FPRef(Z3_mk_fpa_to_fp_bv(ctx.ref(), v.ast, sort.ast), ctx)
10956
10957
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 10666 of file z3py.py.

10666def fpDiv(rm, a, b, ctx=None):
10667 """Create a Z3 floating-point division expression.
10668
10669 >>> s = FPSort(8, 24)
10670 >>> rm = RNE()
10671 >>> x = FP('x', s)
10672 >>> y = FP('y', s)
10673 >>> fpDiv(rm, x, y)
10674 x / y
10675 >>> fpDiv(rm, x, y).sort()
10676 FPSort(8, 24)
10677 """
10678 return _mk_fp_bin(Z3_mk_fpa_div, rm, a, b, ctx)
10679
10680

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

10849def fpEQ(a, b, ctx=None):
10850 """Create the Z3 floating-point expression `fpEQ(other, self)`.
10851
10852 >>> x, y = FPs('x y', FPSort(8, 24))
10853 >>> fpEQ(x, y)
10854 fpEQ(x, y)
10855 >>> fpEQ(x, y).sexpr()
10856 '(fp.eq x y)'
10857 """
10858 return _mk_fp_bin_pred(Z3_mk_fpa_eq, a, b, ctx)
10859
10860

◆ fpFMA()

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

Definition at line 10725 of file z3py.py.

10725def fpFMA(rm, a, b, c, ctx=None):
10726 """Create a Z3 floating-point fused multiply-add expression.
10727 """
10728 return _mk_fp_tern(Z3_mk_fpa_fma, rm, a, b, c, ctx)
10729
10730

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

10873def fpFP(sgn, exp, sig, ctx=None):
10874 """Create the Z3 floating-point value `fpFP(sgn, sig, exp)` from the three bit-vectors sgn, sig, and exp.
10875
10876 >>> s = FPSort(8, 24)
10877 >>> x = fpFP(BitVecVal(1, 1), BitVecVal(2**7-1, 8), BitVecVal(2**22, 23))
10878 >>> print(x)
10879 fpFP(1, 127, 4194304)
10880 >>> xv = FPVal(-1.5, s)
10881 >>> print(xv)
10882 -1.5
10883 >>> slvr = Solver()
10884 >>> slvr.add(fpEQ(x, xv))
10885 >>> slvr.check()
10886 sat
10887 >>> xv = FPVal(+1.5, s)
10888 >>> print(xv)
10889 1.5
10890 >>> slvr = Solver()
10891 >>> slvr.add(fpEQ(x, xv))
10892 >>> slvr.check()
10893 unsat
10894 """
10895 _z3_assert(is_bv(sgn) and is_bv(exp) and is_bv(sig), "sort mismatch")
10896 _z3_assert(sgn.sort().size() == 1, "sort mismatch")
10897 ctx = _get_ctx(ctx)
10898 _z3_assert(ctx == sgn.ctx == exp.ctx == sig.ctx, "context mismatch")
10899 return FPRef(Z3_mk_fpa_fp(ctx.ref(), sgn.ast, exp.ast, sig.ast), ctx)
10900
10901
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 10958 of file z3py.py.

10958def fpFPToFP(rm, v, sort, ctx=None):
10959 """Create a Z3 floating-point conversion expression that represents the
10960 conversion from a floating-point term to a floating-point term of different precision.
10961
10962 >>> x_sgl = FPVal(1.0, Float32())
10963 >>> x_dbl = fpFPToFP(RNE(), x_sgl, Float64())
10964 >>> x_dbl
10965 fpToFP(RNE(), 1)
10966 >>> simplify(x_dbl)
10967 1
10968 >>> x_dbl.sort()
10969 FPSort(11, 53)
10970 """
10971 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10972 _z3_assert(is_fp(v), "Second argument must be a Z3 floating-point expression.")
10973 _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
10974 ctx = _get_ctx(ctx)
10975 return FPRef(Z3_mk_fpa_to_fp_float(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
10976
10977
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 10837 of file z3py.py.

10837def fpGEQ(a, b, ctx=None):
10838 """Create the Z3 floating-point expression `other >= self`.
10839
10840 >>> x, y = FPs('x y', FPSort(8, 24))
10841 >>> fpGEQ(x, y)
10842 x >= y
10843 >>> (x >= y).sexpr()
10844 '(fp.geq x y)'
10845 """
10846 return _mk_fp_bin_pred(Z3_mk_fpa_geq, a, b, ctx)
10847
10848

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

10825def fpGT(a, b, ctx=None):
10826 """Create the Z3 floating-point expression `other > self`.
10827
10828 >>> x, y = FPs('x y', FPSort(8, 24))
10829 >>> fpGT(x, y)
10830 x > y
10831 >>> (x > y).sexpr()
10832 '(fp.gt x y)'
10833 """
10834 return _mk_fp_bin_pred(Z3_mk_fpa_gt, a, b, ctx)
10835
10836

◆ fpInfinity()

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

Definition at line 10413 of file z3py.py.

10413def fpInfinity(s, negative):
10414 """Create a Z3 floating-point +oo or -oo term."""
10415 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10416 _z3_assert(isinstance(negative, bool), "expected Boolean flag")
10417 return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, negative), s.ctx)
10418
10419
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 10755 of file z3py.py.

10755def fpIsInf(a, ctx=None):
10756 """Create a Z3 floating-point isInfinite expression.
10757
10758 >>> s = FPSort(8, 24)
10759 >>> x = FP('x', s)
10760 >>> fpIsInf(x)
10761 fpIsInf(x)
10762 """
10763 return _mk_fp_unary_pred(Z3_mk_fpa_is_infinite, a, ctx)
10764
10765

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

10743def fpIsNaN(a, ctx=None):
10744 """Create a Z3 floating-point isNaN expression.
10745
10746 >>> s = FPSort(8, 24)
10747 >>> x = FP('x', s)
10748 >>> y = FP('y', s)
10749 >>> fpIsNaN(x)
10750 fpIsNaN(x)
10751 """
10752 return _mk_fp_unary_pred(Z3_mk_fpa_is_nan, a, ctx)
10753
10754

◆ fpIsNegative()

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

Definition at line 10784 of file z3py.py.

10784def fpIsNegative(a, ctx=None):
10785 """Create a Z3 floating-point isNegative expression.
10786 """
10787 return _mk_fp_unary_pred(Z3_mk_fpa_is_negative, a, ctx)
10788
10789

◆ fpIsNormal()

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

Definition at line 10772 of file z3py.py.

10772def fpIsNormal(a, ctx=None):
10773 """Create a Z3 floating-point isNormal expression.
10774 """
10775 return _mk_fp_unary_pred(Z3_mk_fpa_is_normal, a, ctx)
10776
10777

◆ fpIsPositive()

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

Definition at line 10790 of file z3py.py.

10790def fpIsPositive(a, ctx=None):
10791 """Create a Z3 floating-point isPositive expression.
10792 """
10793 return _mk_fp_unary_pred(Z3_mk_fpa_is_positive, a, ctx)
10794
10795

◆ fpIsSubnormal()

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

Definition at line 10778 of file z3py.py.

10778def fpIsSubnormal(a, ctx=None):
10779 """Create a Z3 floating-point isSubnormal expression.
10780 """
10781 return _mk_fp_unary_pred(Z3_mk_fpa_is_subnormal, a, ctx)
10782
10783

◆ fpIsZero()

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

Definition at line 10766 of file z3py.py.

10766def fpIsZero(a, ctx=None):
10767 """Create a Z3 floating-point isZero expression.
10768 """
10769 return _mk_fp_unary_pred(Z3_mk_fpa_is_zero, a, ctx)
10770
10771

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

10813def fpLEQ(a, b, ctx=None):
10814 """Create the Z3 floating-point expression `other <= self`.
10815
10816 >>> x, y = FPs('x y', FPSort(8, 24))
10817 >>> fpLEQ(x, y)
10818 x <= y
10819 >>> (x <= y).sexpr()
10820 '(fp.leq x y)'
10821 """
10822 return _mk_fp_bin_pred(Z3_mk_fpa_leq, a, b, ctx)
10823
10824

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

10801def fpLT(a, b, ctx=None):
10802 """Create the Z3 floating-point expression `other < self`.
10803
10804 >>> x, y = FPs('x y', FPSort(8, 24))
10805 >>> fpLT(x, y)
10806 x < y
10807 >>> (x < y).sexpr()
10808 '(fp.lt x y)'
10809 """
10810 return _mk_fp_bin_pred(Z3_mk_fpa_lt, a, b, ctx)
10811
10812

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

10710def fpMax(a, b, ctx=None):
10711 """Create a Z3 floating-point maximum expression.
10712
10713 >>> s = FPSort(8, 24)
10714 >>> rm = RNE()
10715 >>> x = FP('x', s)
10716 >>> y = FP('y', s)
10717 >>> fpMax(x, y)
10718 fpMax(x, y)
10719 >>> fpMax(x, y).sort()
10720 FPSort(8, 24)
10721 """
10722 return _mk_fp_bin_norm(Z3_mk_fpa_max, a, b, ctx)
10723
10724

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

10695def fpMin(a, b, ctx=None):
10696 """Create a Z3 floating-point minimum expression.
10697
10698 >>> s = FPSort(8, 24)
10699 >>> rm = RNE()
10700 >>> x = FP('x', s)
10701 >>> y = FP('y', s)
10702 >>> fpMin(x, y)
10703 fpMin(x, y)
10704 >>> fpMin(x, y).sort()
10705 FPSort(8, 24)
10706 """
10707 return _mk_fp_bin_norm(Z3_mk_fpa_min, a, b, ctx)
10708
10709

◆ fpMinusInfinity()

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

Definition at line 10407 of file z3py.py.

10407def fpMinusInfinity(s):
10408 """Create a Z3 floating-point -oo term."""
10409 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10410 return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, True), s.ctx)
10411
10412

◆ fpMinusZero()

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

Definition at line 10426 of file z3py.py.

10426def fpMinusZero(s):
10427 """Create a Z3 floating-point -0.0 term."""
10428 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10429 return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, True), s.ctx)
10430
10431
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 10651 of file z3py.py.

10651def fpMul(rm, a, b, ctx=None):
10652 """Create a Z3 floating-point multiplication expression.
10653
10654 >>> s = FPSort(8, 24)
10655 >>> rm = RNE()
10656 >>> x = FP('x', s)
10657 >>> y = FP('y', s)
10658 >>> fpMul(rm, x, y)
10659 x * y
10660 >>> fpMul(rm, x, y).sort()
10661 FPSort(8, 24)
10662 """
10663 return _mk_fp_bin(Z3_mk_fpa_mul, rm, a, b, ctx)
10664
10665

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

10373def fpNaN(s):
10374 """Create a Z3 floating-point NaN term.
10375
10376 >>> s = FPSort(8, 24)
10377 >>> set_fpa_pretty(True)
10378 >>> fpNaN(s)
10379 NaN
10380 >>> pb = get_fpa_pretty()
10381 >>> set_fpa_pretty(False)
10382 >>> fpNaN(s)
10383 fpNaN(FPSort(8, 24))
10384 >>> set_fpa_pretty(pb)
10385 """
10386 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10387 return FPNumRef(Z3_mk_fpa_nan(s.ctx_ref(), s.ast), s.ctx)
10388
10389
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 10551 of file z3py.py.

10551def fpNeg(a, ctx=None):
10552 """Create a Z3 floating-point addition expression.
10553
10554 >>> s = FPSort(8, 24)
10555 >>> rm = RNE()
10556 >>> x = FP('x', s)
10557 >>> fpNeg(x)
10558 -x
10559 >>> fpNeg(x).sort()
10560 FPSort(8, 24)
10561 """
10562 ctx = _get_ctx(ctx)
10563 [a] = _coerce_fp_expr_list([a], ctx)
10564 return FPRef(Z3_mk_fpa_neg(ctx.ref(), a.as_ast()), ctx)
10565
10566
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 10861 of file z3py.py.

10861def fpNEQ(a, b, ctx=None):
10862 """Create the Z3 floating-point expression `Not(fpEQ(other, self))`.
10863
10864 >>> x, y = FPs('x y', FPSort(8, 24))
10865 >>> fpNEQ(x, y)
10866 Not(fpEQ(x, y))
10867 >>> (x != y).sexpr()
10868 '(distinct x y)'
10869 """
10870 return Not(fpEQ(a, b, ctx))
10871
10872

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

10390def fpPlusInfinity(s):
10391 """Create a Z3 floating-point +oo term.
10392
10393 >>> s = FPSort(8, 24)
10394 >>> pb = get_fpa_pretty()
10395 >>> set_fpa_pretty(True)
10396 >>> fpPlusInfinity(s)
10397 +oo
10398 >>> set_fpa_pretty(False)
10399 >>> fpPlusInfinity(s)
10400 fpPlusInfinity(FPSort(8, 24))
10401 >>> set_fpa_pretty(pb)
10402 """
10403 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10404 return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, False), s.ctx)
10405
10406

◆ fpPlusZero()

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

Definition at line 10420 of file z3py.py.

10420def fpPlusZero(s):
10421 """Create a Z3 floating-point +0.0 term."""
10422 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10423 return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, False), s.ctx)
10424
10425

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

10978def fpRealToFP(rm, v, sort, ctx=None):
10979 """Create a Z3 floating-point conversion expression that represents the
10980 conversion from a real term to a floating-point term.
10981
10982 >>> x_r = RealVal(1.5)
10983 >>> x_fp = fpRealToFP(RNE(), x_r, Float32())
10984 >>> x_fp
10985 fpToFP(RNE(), 3/2)
10986 >>> simplify(x_fp)
10987 1.5
10988 """
10989 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10990 _z3_assert(is_real(v), "Second argument must be a Z3 expression or real sort.")
10991 _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
10992 ctx = _get_ctx(ctx)
10993 return FPRef(Z3_mk_fpa_to_fp_real(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
10994
10995
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 10681 of file z3py.py.

10681def fpRem(a, b, ctx=None):
10682 """Create a Z3 floating-point remainder expression.
10683
10684 >>> s = FPSort(8, 24)
10685 >>> x = FP('x', s)
10686 >>> y = FP('y', s)
10687 >>> fpRem(x, y)
10688 fpRem(x, y)
10689 >>> fpRem(x, y).sort()
10690 FPSort(8, 24)
10691 """
10692 return _mk_fp_bin_norm(Z3_mk_fpa_rem, a, b, ctx)
10693
10694

◆ fpRoundToIntegral()

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

Definition at line 10737 of file z3py.py.

10737def fpRoundToIntegral(rm, a, ctx=None):
10738 """Create a Z3 floating-point roundToIntegral expression.
10739 """
10740 return _mk_fp_unary(Z3_mk_fpa_round_to_integral, rm, a, ctx)
10741
10742

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

10509def FPs(names, fpsort, ctx=None):
10510 """Return an array of floating-point constants.
10511
10512 >>> x, y, z = FPs('x y z', FPSort(8, 24))
10513 >>> x.sort()
10514 FPSort(8, 24)
10515 >>> x.sbits()
10516 24
10517 >>> x.ebits()
10518 8
10519 >>> fpMul(RNE(), fpAdd(RNE(), x, y), z)
10520 (x + y) * z
10521 """
10522 ctx = _get_ctx(ctx)
10523 if isinstance(names, str):
10524 names = names.split(" ")
10525 return [FP(name, fpsort, ctx) for name in names]
10526
10527

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

10996def fpSignedToFP(rm, v, sort, ctx=None):
10997 """Create a Z3 floating-point conversion expression that represents the
10998 conversion from a signed bit-vector term (encoding an integer) to a floating-point term.
10999
11000 >>> x_signed = BitVecVal(-5, BitVecSort(32))
11001 >>> x_fp = fpSignedToFP(RNE(), x_signed, Float32())
11002 >>> x_fp
11003 fpToFP(RNE(), 4294967291)
11004 >>> simplify(x_fp)
11005 -1.25*(2**2)
11006 """
11007 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
11008 _z3_assert(is_bv(v), "Second argument must be a Z3 bit-vector expression")
11009 _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
11010 ctx = _get_ctx(ctx)
11011 return FPRef(Z3_mk_fpa_to_fp_signed(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
11012
11013
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 10314 of file z3py.py.

10314def FPSort(ebits, sbits, ctx=None):
10315 """Return a Z3 floating-point sort of the given sizes. If `ctx=None`, then the global context is used.
10316
10317 >>> Single = FPSort(8, 24)
10318 >>> Double = FPSort(11, 53)
10319 >>> Single
10320 FPSort(8, 24)
10321 >>> x = Const('x', Single)
10322 >>> eq(x, FP('x', FPSort(8, 24)))
10323 True
10324 """
10325 ctx = _get_ctx(ctx)
10326 return FPSortRef(Z3_mk_fpa_sort(ctx.ref(), ebits, sbits), ctx)
10327
10328
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 10731 of file z3py.py.

10731def fpSqrt(rm, a, ctx=None):
10732 """Create a Z3 floating-point square root expression.
10733 """
10734 return _mk_fp_unary(Z3_mk_fpa_sqrt, rm, a, ctx)
10735
10736

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

10636def fpSub(rm, a, b, ctx=None):
10637 """Create a Z3 floating-point subtraction expression.
10638
10639 >>> s = FPSort(8, 24)
10640 >>> rm = RNE()
10641 >>> x = FP('x', s)
10642 >>> y = FP('y', s)
10643 >>> fpSub(rm, x, y)
10644 x - y
10645 >>> fpSub(rm, x, y).sort()
10646 FPSort(8, 24)
10647 """
10648 return _mk_fp_bin(Z3_mk_fpa_sub, rm, a, b, ctx)
10649
10650

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

10902def fpToFP(a1, a2=None, a3=None, ctx=None):
10903 """Create a Z3 floating-point conversion expression from other term sorts
10904 to floating-point.
10905
10906 From a bit-vector term in IEEE 754-2008 format:
10907 >>> x = FPVal(1.0, Float32())
10908 >>> x_bv = fpToIEEEBV(x)
10909 >>> simplify(fpToFP(x_bv, Float32()))
10910 1
10911
10912 From a floating-point term with different precision:
10913 >>> x = FPVal(1.0, Float32())
10914 >>> x_db = fpToFP(RNE(), x, Float64())
10915 >>> x_db.sort()
10916 FPSort(11, 53)
10917
10918 From a real term:
10919 >>> x_r = RealVal(1.5)
10920 >>> simplify(fpToFP(RNE(), x_r, Float32()))
10921 1.5
10922
10923 From a signed bit-vector term:
10924 >>> x_signed = BitVecVal(-5, BitVecSort(32))
10925 >>> simplify(fpToFP(RNE(), x_signed, Float32()))
10926 -1.25*(2**2)
10927 """
10928 ctx = _get_ctx(ctx)
10929 if is_bv(a1) and is_fp_sort(a2):
10930 return FPRef(Z3_mk_fpa_to_fp_bv(ctx.ref(), a1.ast, a2.ast), ctx)
10931 elif is_fprm(a1) and is_fp(a2) and is_fp_sort(a3):
10932 return FPRef(Z3_mk_fpa_to_fp_float(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
10933 elif is_fprm(a1) and is_real(a2) and is_fp_sort(a3):
10934 return FPRef(Z3_mk_fpa_to_fp_real(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
10935 elif is_fprm(a1) and is_bv(a2) and is_fp_sort(a3):
10936 return FPRef(Z3_mk_fpa_to_fp_signed(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
10937 else:
10938 raise Z3Exception("Unsupported combination of arguments for conversion to floating-point term.")
10939
10940

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

11032def fpToFPUnsigned(rm, x, s, ctx=None):
11033 """Create a Z3 floating-point conversion expression, from unsigned bit-vector to floating-point expression."""
11034 if z3_debug():
11035 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
11036 _z3_assert(is_bv(x), "Second argument must be a Z3 bit-vector expression")
11037 _z3_assert(is_fp_sort(s), "Third argument must be Z3 floating-point sort")
11038 ctx = _get_ctx(ctx)
11039 return FPRef(Z3_mk_fpa_to_fp_unsigned(ctx.ref(), rm.ast, x.ast, s.ast), ctx)
11040
11041
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 11106 of file z3py.py.

11106def fpToIEEEBV(x, ctx=None):
11107 """\brief Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.
11108
11109 The size of the resulting bit-vector is automatically determined.
11110
11111 Note that IEEE 754-2008 allows multiple different representations of NaN. This conversion
11112 knows only one NaN and it will always produce the same bit-vector representation of
11113 that NaN.
11114
11115 >>> x = FP('x', FPSort(8, 24))
11116 >>> y = fpToIEEEBV(x)
11117 >>> print(is_fp(x))
11118 True
11119 >>> print(is_bv(y))
11120 True
11121 >>> print(is_fp(y))
11122 False
11123 >>> print(is_bv(x))
11124 False
11125 """
11126 if z3_debug():
11127 _z3_assert(is_fp(x), "First argument must be a Z3 floating-point expression")
11128 ctx = _get_ctx(ctx)
11129 return BitVecRef(Z3_mk_fpa_to_ieee_bv(ctx.ref(), x.ast), ctx)
11130
11131
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 11086 of file z3py.py.

11086def fpToReal(x, ctx=None):
11087 """Create a Z3 floating-point conversion expression, from floating-point expression to real.
11088
11089 >>> x = FP('x', FPSort(8, 24))
11090 >>> y = fpToReal(x)
11091 >>> print(is_fp(x))
11092 True
11093 >>> print(is_real(y))
11094 True
11095 >>> print(is_fp(y))
11096 False
11097 >>> print(is_real(x))
11098 False
11099 """
11100 if z3_debug():
11101 _z3_assert(is_fp(x), "First argument must be a Z3 floating-point expression")
11102 ctx = _get_ctx(ctx)
11103 return ArithRef(Z3_mk_fpa_to_real(ctx.ref(), x.ast), ctx)
11104
11105
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 11042 of file z3py.py.

11042def fpToSBV(rm, x, s, ctx=None):
11043 """Create a Z3 floating-point conversion expression, from floating-point expression to signed bit-vector.
11044
11045 >>> x = FP('x', FPSort(8, 24))
11046 >>> y = fpToSBV(RTZ(), x, BitVecSort(32))
11047 >>> print(is_fp(x))
11048 True
11049 >>> print(is_bv(y))
11050 True
11051 >>> print(is_fp(y))
11052 False
11053 >>> print(is_bv(x))
11054 False
11055 """
11056 if z3_debug():
11057 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
11058 _z3_assert(is_fp(x), "Second argument must be a Z3 floating-point expression")
11059 _z3_assert(is_bv_sort(s), "Third argument must be Z3 bit-vector sort")
11060 ctx = _get_ctx(ctx)
11061 return BitVecRef(Z3_mk_fpa_to_sbv(ctx.ref(), rm.ast, x.ast, s.size()), ctx)
11062
11063
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 11064 of file z3py.py.

11064def fpToUBV(rm, x, s, ctx=None):
11065 """Create a Z3 floating-point conversion expression, from floating-point expression to unsigned bit-vector.
11066
11067 >>> x = FP('x', FPSort(8, 24))
11068 >>> y = fpToUBV(RTZ(), x, BitVecSort(32))
11069 >>> print(is_fp(x))
11070 True
11071 >>> print(is_bv(y))
11072 True
11073 >>> print(is_fp(y))
11074 False
11075 >>> print(is_bv(x))
11076 False
11077 """
11078 if z3_debug():
11079 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
11080 _z3_assert(is_fp(x), "Second argument must be a Z3 floating-point expression")
11081 _z3_assert(is_bv_sort(s), "Third argument must be Z3 bit-vector sort")
11082 ctx = _get_ctx(ctx)
11083 return BitVecRef(Z3_mk_fpa_to_ubv(ctx.ref(), rm.ast, x.ast, s.size()), ctx)
11084
11085
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 11014 of file z3py.py.

11014def fpUnsignedToFP(rm, v, sort, ctx=None):
11015 """Create a Z3 floating-point conversion expression that represents the
11016 conversion from an unsigned bit-vector term (encoding an integer) to a floating-point term.
11017
11018 >>> x_signed = BitVecVal(-5, BitVecSort(32))
11019 >>> x_fp = fpUnsignedToFP(RNE(), x_signed, Float32())
11020 >>> x_fp
11021 fpToFPUnsigned(RNE(), 4294967291)
11022 >>> simplify(x_fp)
11023 1*(2**32)
11024 """
11025 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
11026 _z3_assert(is_bv(v), "Second argument must be a Z3 bit-vector expression")
11027 _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
11028 ctx = _get_ctx(ctx)
11029 return FPRef(Z3_mk_fpa_to_fp_unsigned(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
11030
11031

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

10439def FPVal(sig, exp=None, fps=None, ctx=None):
10440 """Return a floating-point value of value `val` and sort `fps`.
10441 If `ctx=None`, then the global context is used.
10442
10443 >>> v = FPVal(20.0, FPSort(8, 24))
10444 >>> v
10445 1.25*(2**4)
10446 >>> print("0x%.8x" % v.exponent_as_long(False))
10447 0x00000004
10448 >>> v = FPVal(2.25, FPSort(8, 24))
10449 >>> v
10450 1.125*(2**1)
10451 >>> v = FPVal(-2.25, FPSort(8, 24))
10452 >>> v
10453 -1.125*(2**1)
10454 >>> FPVal(-0.0, FPSort(8, 24))
10455 -0.0
10456 >>> FPVal(0.0, FPSort(8, 24))
10457 +0.0
10458 >>> FPVal(+0.0, FPSort(8, 24))
10459 +0.0
10460 """
10461 ctx = _get_ctx(ctx)
10462 if is_fp_sort(exp):
10463 fps = exp
10464 exp = None
10465 elif fps is None:
10466 fps = _dflt_fps(ctx)
10467 _z3_assert(is_fp_sort(fps), "sort mismatch")
10468 if exp is None:
10469 exp = 0
10470 val = _to_float_str(sig)
10471 if val == "NaN" or val == "nan":
10472 return fpNaN(fps)
10473 elif val == "-0.0":
10474 return fpMinusZero(fps)
10475 elif val == "0.0" or val == "+0.0":
10476 return fpPlusZero(fps)
10477 elif val == "+oo" or val == "+inf" or val == "+Inf":
10478 return fpPlusInfinity(fps)
10479 elif val == "-oo" or val == "-inf" or val == "-Inf":
10480 return fpMinusInfinity(fps)
10481 else:
10482 return FPNumRef(Z3_mk_numeral(ctx.ref(), val, fps.ast), ctx)
10483
10484

◆ fpZero()

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

Definition at line 10432 of file z3py.py.

10432def fpZero(s, negative):
10433 """Create a Z3 floating-point +0.0 or -0.0 term."""
10434 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10435 _z3_assert(isinstance(negative, bool), "expected Boolean flag")
10436 return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, negative), s.ctx)
10437
10438

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

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

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

◆ FreshFunction()

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

Definition at line 943 of file z3py.py.

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

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

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

3504def FreshReal(prefix="b", ctx=None):
3505 """Return a fresh real constant in the given context using the given prefix.
3506
3507 >>> x = FreshReal()
3508 >>> y = FreshReal()
3509 >>> eq(x, y)
3510 False
3511 >>> x.sort()
3512 Real
3513 """
3514 ctx = _get_ctx(ctx)
3515 return ArithRef(Z3_mk_fresh_const(ctx.ref(), prefix, RealSort(ctx).ast), ctx)
3516
3517

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

11409def Full(s):
11410 """Create the regular expression that accepts the universal language
11411 >>> e = Full(ReSort(SeqSort(IntSort())))
11412 >>> print(e)
11413 Full(ReSort(Seq(Int)))
11414 >>> e1 = Full(ReSort(StringSort()))
11415 >>> print(e1)
11416 Full(ReSort(String))
11417 """
11418 if isinstance(s, ReSortRef):
11419 return ReRef(Z3_mk_re_full(s.ctx_ref(), s.ast), s.ctx)
11420 raise Z3Exception("Non-sequence, non-regular expression sort passed to Full")
11421
11422
11423
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 5114 of file z3py.py.

5114def FullSet(s):
5115 """Create the full set
5116 >>> FullSet(IntSort())
5117 K(Int, True)
5118 """
5119 ctx = s.ctx
5120 return ArrayRef(Z3_mk_full_set(ctx.ref(), s.ast), ctx)
5121
5122
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 920 of file z3py.py.

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

6961def get_as_array_func(n):
6962 """Return the function declaration f associated with a Z3 expression of the form (_ as-array f)."""
6963 if z3_debug():
6964 _z3_assert(is_as_array(n), "as-array Z3 expression expected.")
6965 return FuncDeclRef(Z3_get_as_array_func_decl(n.ctx.ref(), n.as_ast()), n.ctx)
6966
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 294 of file z3py.py.

294def get_ctx(ctx) -> Context:
295 return _get_ctx(ctx)
296
297

◆ get_default_fp_sort()

get_default_fp_sort (   ctx = None)

Definition at line 9726 of file z3py.py.

9726def get_default_fp_sort(ctx=None):
9727 return FPSort(_dflt_fpsort_ebits, _dflt_fpsort_sbits, ctx)
9728
9729

◆ get_default_rounding_mode()

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

Definition at line 9693 of file z3py.py.

9693def get_default_rounding_mode(ctx=None):
9694 """Retrieves the global default rounding mode."""
9695 global _dflt_rounding_mode
9696 if _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO:
9697 return RTZ(ctx)
9698 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE:
9699 return RTN(ctx)
9700 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE:
9701 return RTP(ctx)
9702 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN:
9703 return RNE(ctx)
9704 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY:
9705 return RNA(ctx)
9706
9707

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

4866def get_map_func(a):
4867 """Return the function declaration associated with a Z3 map array expression.
4868
4869 >>> f = Function('f', IntSort(), IntSort())
4870 >>> b = Array('b', IntSort(), IntSort())
4871 >>> a = Map(f, b)
4872 >>> eq(f, get_map_func(a))
4873 True
4874 >>> get_map_func(a)
4875 f
4876 >>> get_map_func(a)(0)
4877 f(0)
4878 """
4879 if z3_debug():
4880 _z3_assert(is_map(a), "Z3 array map expression expected.")
4881 return FuncDeclRef(
4883 a.ctx_ref(),
4884 Z3_get_decl_ast_parameter(a.ctx_ref(), a.decl().ast, 0),
4885 ),
4886 ctx=a.ctx,
4887 )
4888
4889
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 334 of file z3py.py.

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

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

9199def help_simplify():
9200 """Return a string describing all options available for Z3 `simplify` procedure."""
9201 print(Z3_simplify_get_help(main_ctx().ref()))
9202
9203
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 1484 of file z3py.py.

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

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

11493def IndexOf(s, substr, offset=None):
11494 """Retrieve the index of substring within a string starting at a specified offset.
11495 >>> simplify(IndexOf("abcabc", "bc", 0))
11496 1
11497 >>> simplify(IndexOf("abcabc", "bc", 2))
11498 4
11499 """
11500 if offset is None:
11501 offset = IntVal(0)
11502 ctx = None
11503 if is_expr(offset):
11504 ctx = offset.ctx
11505 ctx = _get_ctx2(s, substr, ctx)
11506 s = _coerce_seq(s, ctx)
11507 substr = _coerce_seq(substr, ctx)
11508 if _is_int(offset):
11509 offset = IntVal(offset, ctx)
11510 return ArithRef(Z3_mk_seq_index(s.ctx_ref(), s.as_ast(), substr.as_ast(), offset.as_ast()), s.ctx)
11511
11512
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 11632 of file z3py.py.

11632def InRe(s, re):
11633 """Create regular expression membership test
11634 >>> re = Union(Re("a"),Re("b"))
11635 >>> print (simplify(InRe("a", re)))
11636 True
11637 >>> print (simplify(InRe("b", re)))
11638 True
11639 >>> print (simplify(InRe("c", re)))
11640 False
11641 """
11642 s = _coerce_seq(s, re.ctx)
11643 return BoolRef(Z3_mk_seq_in_re(s.ctx_ref(), s.as_ast(), re.as_ast()), s.ctx)
11644
11645
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 3408 of file z3py.py.

3408def Int(name, ctx=None):
3409 """Return an integer constant named `name`. If `ctx=None`, then the global context is used.
3410
3411 >>> x = Int('x')
3412 >>> is_int(x)
3413 True
3414 >>> is_int(x + 1)
3415 True
3416 """
3417 ctx = _get_ctx(ctx)
3418 return ArithRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), IntSort(ctx).ast), ctx)
3419
3420

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

4163def Int2BV(a, num_bits):
4164 """Return the z3 expression Int2BV(a, num_bits).
4165 It is a bit-vector of width num_bits and represents the
4166 modulo of a by 2^num_bits
4167 """
4168 ctx = a.ctx
4169 return BitVecRef(Z3_mk_int2bv(ctx.ref(), num_bits, a.as_ast()), ctx)
4170
4171
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 11666 of file z3py.py.

11666def Intersect(*args):
11667 """Create intersection of regular expressions.
11668 >>> re = Intersect(Re("a"), Re("b"), Re("c"))
11669 """
11670 args = _get_args(args)
11671 sz = len(args)
11672 if z3_debug():
11673 _z3_assert(sz > 0, "At least one argument expected.")
11674 _z3_assert(all([is_re(a) for a in args]), "All arguments must be regular expressions.")
11675 if sz == 1:
11676 return args[0]
11677 ctx = args[0].ctx
11678 v = (Ast * sz)()
11679 for i in range(sz):
11680 v[i] = args[i].as_ast()
11681 return ReRef(Z3_mk_re_intersect(ctx.ref(), sz, v), ctx)
11682
11683
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 3421 of file z3py.py.

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

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

3298def IntSort(ctx=None):
3299 """Return the integer sort in the given context. If `ctx=None`, then the global context is used.
3300
3301 >>> IntSort()
3302 Int
3303 >>> x = Const('x', IntSort())
3304 >>> is_int(x)
3305 True
3306 >>> x.sort() == IntSort()
3307 True
3308 >>> x.sort() == BoolSort()
3309 False
3310 """
3311 ctx = _get_ctx(ctx)
3312 return ArithSortRef(Z3_mk_int_sort(ctx.ref()), ctx)
3313
3314
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 11574 of file z3py.py.

11574def IntToStr(s):
11575 """Convert integer expression to string"""
11576 if not is_expr(s):
11577 s = _py2expr(s)
11578 return SeqRef(Z3_mk_int_to_str(s.ctx_ref(), s.as_ast()), s.ctx)
11579
11580
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 3344 of file z3py.py.

3344def IntVal(val, ctx=None):
3345 """Return a Z3 integer value. If `ctx=None`, then the global context is used.
3346
3347 >>> IntVal(1)
3348 1
3349 >>> IntVal("100")
3350 100
3351 """
3352 ctx = _get_ctx(ctx)
3353 return IntNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), IntSort(ctx).ast), ctx)
3354
3355

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

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

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

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

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

2932def is_algebraic_value(a):
2933 """Return `True` if `a` is an algebraic value of sort Real.
2934
2935 >>> is_algebraic_value(RealVal("3/5"))
2936 False
2937 >>> n = simplify(Sqrt(2))
2938 >>> n
2939 1.4142135623?
2940 >>> is_algebraic_value(n)
2941 True
2942 """
2943 return is_arith(a) and a.is_real() and _is_algebraic(a.ctx, a.as_ast())
2944
2945

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

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

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

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

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

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

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

2819def is_arith(a):
2820 """Return `True` if `a` is an arithmetical expression.
2821
2822 >>> x = Int('x')
2823 >>> is_arith(x)
2824 True
2825 >>> is_arith(x + 1)
2826 True
2827 >>> is_arith(1)
2828 False
2829 >>> is_arith(IntVal(1))
2830 True
2831 >>> y = Real('y')
2832 >>> is_arith(y)
2833 True
2834 >>> is_arith(y + 1)
2835 True
2836 """
2837 return isinstance(a, ArithRef)
2838
2839

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

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

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

4801def is_array(a : Any) -> bool:
4802 """Return `True` if `a` is a Z3 array expression.
4803
4804 >>> a = Array('a', IntSort(), IntSort())
4805 >>> is_array(a)
4806 True
4807 >>> is_array(Store(a, 0, 1))
4808 True
4809 >>> is_array(a[0])
4810 False
4811 """
4812 return isinstance(a, ArrayRef)
4813
4814

Referenced by Ext(), and Map().

◆ is_array_sort()

is_array_sort (   a)

Definition at line 4797 of file z3py.py.

4797def is_array_sort(a):
4798 return Z3_get_sort_kind(a.ctx.ref(), Z3_get_sort(a.ctx.ref(), a.ast)) == Z3_ARRAY_SORT
4799
4800

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

6956def is_as_array(n):
6957 """Return true if n is a Z3 expression of the form (_ as-array f)."""
6958 return isinstance(n, ExprRef) and Z3_is_as_array(n.ctx.ref(), n.as_ast())
6959
6960
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 482 of file z3py.py.

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

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

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

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

4111def is_bv(a):
4112 """Return `True` if `a` is a Z3 bit-vector expression.
4113
4114 >>> b = BitVec('b', 32)
4115 >>> is_bv(b)
4116 True
4117 >>> is_bv(b + 10)
4118 True
4119 >>> is_bv(Int('x'))
4120 False
4121 """
4122 return isinstance(a, BitVecRef)
4123
4124

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

3638def is_bv_sort(s):
3639 """Return True if `s` is a Z3 bit-vector sort.
3640
3641 >>> is_bv_sort(BitVecSort(32))
3642 True
3643 >>> is_bv_sort(IntSort())
3644 False
3645 """
3646 return isinstance(s, BitVecSortRef)
3647
3648

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

4125def is_bv_value(a):
4126 """Return `True` if `a` is a Z3 bit-vector numeral value.
4127
4128 >>> b = BitVec('b', 32)
4129 >>> is_bv_value(b)
4130 False
4131 >>> b = BitVecVal(10, 32)
4132 >>> b
4133 10
4134 >>> is_bv_value(b)
4135 True
4136 """
4137 return is_bv(a) and _is_numeral(a.ctx, a.as_ast())
4138
4139

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

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

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

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

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

4857def is_default(a):
4858 """Return `True` if `a` is a Z3 default array expression.
4859 >>> d = Default(K(IntSort(), 10))
4860 >>> is_default(d)
4861 True
4862 """
4863 return is_app_of(a, Z3_OP_ARRAY_DEFAULT)
4864
4865

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

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

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

2982def is_div(a : Any) -> bool:
2983 """Return `True` if `a` is an expression of the form b / c.
2984
2985 >>> x, y = Reals('x y')
2986 >>> is_div(x / y)
2987 True
2988 >>> is_div(x + y)
2989 False
2990 >>> x, y = Ints('x y')
2991 >>> is_div(x / y)
2992 False
2993 >>> is_idiv(x / y)
2994 True
2995 """
2996 return is_app_of(a, Z3_OP_DIV)
2997
2998

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

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

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

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

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(), DatatypeRef.update_field(), 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 1740 of file z3py.py.

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

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

8075def is_finite_domain(a):
8076 """Return `True` if `a` is a Z3 finite-domain expression.
8077
8078 >>> s = FiniteDomainSort('S', 100)
8079 >>> b = Const('b', s)
8080 >>> is_finite_domain(b)
8081 True
8082 >>> is_finite_domain(Int('x'))
8083 False
8084 """
8085 return isinstance(a, FiniteDomainRef)
8086
8087

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

8052def is_finite_domain_sort(s):
8053 """Return True if `s` is a Z3 finite-domain sort.
8054
8055 >>> is_finite_domain_sort(FiniteDomainSort('S', 100))
8056 True
8057 >>> is_finite_domain_sort(IntSort())
8058 False
8059 """
8060 return isinstance(s, FiniteDomainSortRef)
8061
8062

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

8129def is_finite_domain_value(a):
8130 """Return `True` if `a` is a Z3 finite-domain value.
8131
8132 >>> s = FiniteDomainSort('S', 100)
8133 >>> b = Const('b', s)
8134 >>> is_finite_domain_value(b)
8135 False
8136 >>> b = FiniteDomainVal(10, s)
8137 >>> b
8138 10
8139 >>> is_finite_domain_value(b)
8140 True
8141 """
8142 return is_finite_domain(a) and _is_numeral(a.ctx, a.as_ast())
8143
8144

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

10285def is_fp(a):
10286 """Return `True` if `a` is a Z3 floating-point expression.
10287
10288 >>> b = FP('b', FPSort(8, 24))
10289 >>> is_fp(b)
10290 True
10291 >>> is_fp(b + 1.0)
10292 True
10293 >>> is_fp(Int('x'))
10294 False
10295 """
10296 return isinstance(a, FPRef)
10297
10298

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

9859def is_fp_sort(s):
9860 """Return True if `s` is a Z3 floating-point sort.
9861
9862 >>> is_fp_sort(FPSort(8, 24))
9863 True
9864 >>> is_fp_sort(IntSort())
9865 False
9866 """
9867 return isinstance(s, FPSortRef)
9868
9869

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

10299def is_fp_value(a):
10300 """Return `True` if `a` is a Z3 floating-point numeral value.
10301
10302 >>> b = FP('b', FPSort(8, 24))
10303 >>> is_fp_value(b)
10304 False
10305 >>> b = FPVal(1.0, FPSort(8, 24))
10306 >>> b
10307 1
10308 >>> is_fp_value(b)
10309 True
10310 """
10311 return is_fp(a) and _is_numeral(a.ctx, a.ast)
10312
10313

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

10119def is_fprm(a):
10120 """Return `True` if `a` is a Z3 floating-point rounding mode expression.
10121
10122 >>> rm = RNE()
10123 >>> is_fprm(rm)
10124 True
10125 >>> rm = 1.0
10126 >>> is_fprm(rm)
10127 False
10128 """
10129 return isinstance(a, FPRMRef)
10130
10131

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

9870def is_fprm_sort(s):
9871 """Return True if `s` is a Z3 floating-point rounding mode sort.
9872
9873 >>> is_fprm_sort(FPSort(8, 24))
9874 False
9875 >>> is_fprm_sort(RNE().sort())
9876 True
9877 """
9878 return isinstance(s, FPRMSortRef)
9879
9880# FP Expressions
9881
9882

◆ is_fprm_value()

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

Definition at line 10132 of file z3py.py.

10132def is_fprm_value(a):
10133 """Return `True` if `a` is a Z3 floating-point rounding mode numeral value."""
10134 return is_fprm(a) and _is_numeral(a.ctx, a.ast)
10135
10136# FP Numerals
10137
10138

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

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

Referenced by Map(), DatatypeRef.update_field(), 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 3047 of file z3py.py.

3047def is_ge(a : Any) -> bool:
3048 """Return `True` if `a` is an expression of the form b >= c.
3049
3050 >>> x, y = Ints('x y')
3051 >>> is_ge(x >= y)
3052 True
3053 >>> is_ge(x == y)
3054 False
3055 """
3056 return is_app_of(a, Z3_OP_GE)
3057
3058

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

3059def is_gt(a : Any) -> bool:
3060 """Return `True` if `a` is an expression of the form b > c.
3061
3062 >>> x, y = Ints('x y')
3063 >>> is_gt(x > y)
3064 True
3065 >>> is_gt(x == y)
3066 False
3067 """
3068 return is_app_of(a, Z3_OP_GT)
3069
3070

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

2999def is_idiv(a : Any) -> bool:
3000 """Return `True` if `a` is an expression of the form b div c.
3001
3002 >>> x, y = Ints('x y')
3003 >>> is_idiv(x / y)
3004 True
3005 >>> is_idiv(x + y)
3006 False
3007 """
3008 return is_app_of(a, Z3_OP_IDIV)
3009
3010

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

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

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

2840def is_int(a) -> bool:
2841 """Return `True` if `a` is an integer expression.
2842
2843 >>> x = Int('x')
2844 >>> is_int(x + 1)
2845 True
2846 >>> is_int(1)
2847 False
2848 >>> is_int(IntVal(1))
2849 True
2850 >>> y = Real('y')
2851 >>> is_int(y)
2852 False
2853 >>> is_int(y + 1)
2854 False
2855 """
2856 return is_arith(a) and a.is_int()
2857
2858

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

2886def is_int_value(a):
2887 """Return `True` if `a` is an integer value of sort Int.
2888
2889 >>> is_int_value(IntVal(1))
2890 True
2891 >>> is_int_value(1)
2892 False
2893 >>> is_int_value(Int('x'))
2894 False
2895 >>> n = Int('x') + 1
2896 >>> n
2897 x + 1
2898 >>> n.arg(1)
2899 1
2900 >>> is_int_value(n.arg(1))
2901 True
2902 >>> is_int_value(RealVal("1/3"))
2903 False
2904 >>> is_int_value(RealVal(1))
2905 False
2906 """
2907 return is_arith(a) and a.is_int() and _is_numeral(a.ctx, a.as_ast())
2908
2909

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

3071def is_is_int(a : Any) -> bool:
3072 """Return `True` if `a` is an expression of the form IsInt(b).
3073
3074 >>> x = Real('x')
3075 >>> is_is_int(IsInt(x))
3076 True
3077 >>> is_is_int(x)
3078 False
3079 """
3080 return is_app_of(a, Z3_OP_IS_INT)
3081
3082

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

4828def is_K(a):
4829 """Return `True` if `a` is a Z3 constant array.
4830
4831 >>> a = K(IntSort(), 10)
4832 >>> is_K(a)
4833 True
4834 >>> a = Array('a', IntSort(), IntSort())
4835 >>> is_K(a)
4836 False
4837 """
4838 return is_app_of(a, Z3_OP_CONST_ARRAY)
4839
4840

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

3023def is_le(a : Any) -> bool:
3024 """Return `True` if `a` is an expression of the form b <= c.
3025
3026 >>> x, y = Ints('x y')
3027 >>> is_le(x <= y)
3028 True
3029 >>> is_le(x < y)
3030 False
3031 """
3032 return is_app_of(a, Z3_OP_LE)
3033
3034

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

3035def is_lt(a : Any) -> bool:
3036 """Return `True` if `a` is an expression of the form b < c.
3037
3038 >>> x, y = Ints('x y')
3039 >>> is_lt(x < y)
3040 True
3041 >>> is_lt(x == y)
3042 False
3043 """
3044 return is_app_of(a, Z3_OP_LT)
3045
3046

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

4841def is_map(a):
4842 """Return `True` if `a` is a Z3 map array expression.
4843
4844 >>> f = Function('f', IntSort(), IntSort())
4845 >>> b = Array('b', IntSort(), IntSort())
4846 >>> a = Map(f, b)
4847 >>> a
4848 Map(f, b)
4849 >>> is_map(a)
4850 True
4851 >>> is_map(b)
4852 False
4853 """
4854 return is_app_of(a, Z3_OP_ARRAY_MAP)
4855
4856

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

3011def is_mod(a : Any) -> bool:
3012 """Return `True` if `a` is an expression of the form b % c.
3013
3014 >>> x, y = Ints('x y')
3015 >>> is_mod(x % y)
3016 True
3017 >>> is_mod(x + y)
3018 False
3019 """
3020 return is_app_of(a, Z3_OP_MOD)
3021
3022

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

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

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

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

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

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

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

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

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

9040def is_probe(p):
9041 """Return `True` if `p` is a Z3 probe.
9042
9043 >>> is_probe(Int('x'))
9044 False
9045 >>> is_probe(Probe('memory'))
9046 True
9047 """
9048 return isinstance(p, Probe)
9049
9050

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

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

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

2910def is_rational_value(a):
2911 """Return `True` if `a` is rational value of sort Real.
2912
2913 >>> is_rational_value(RealVal(1))
2914 True
2915 >>> is_rational_value(RealVal("3/5"))
2916 True
2917 >>> is_rational_value(IntVal(1))
2918 False
2919 >>> is_rational_value(1)
2920 False
2921 >>> n = Real('x') + 1
2922 >>> n.arg(1)
2923 1
2924 >>> is_rational_value(n.arg(1))
2925 True
2926 >>> is_rational_value(Real('x'))
2927 False
2928 """
2929 return is_arith(a) and a.is_real() and _is_numeral(a.ctx, a.as_ast())
2930
2931

◆ is_re()

is_re (   s)

Definition at line 11628 of file z3py.py.

11628def is_re(s):
11629 return isinstance(s, ReRef)
11630
11631

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

2859def is_real(a):
2860 """Return `True` if `a` is a real expression.
2861
2862 >>> x = Int('x')
2863 >>> is_real(x + 1)
2864 False
2865 >>> y = Real('y')
2866 >>> is_real(y)
2867 True
2868 >>> is_real(y + 1)
2869 True
2870 >>> is_real(1)
2871 False
2872 >>> is_real(RealVal(1))
2873 True
2874 """
2875 return is_arith(a) and a.is_real()
2876
2877

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

5069def is_select(a):
5070 """Return `True` if `a` is a Z3 array select application.
5071
5072 >>> a = Array('a', IntSort(), IntSort())
5073 >>> is_select(a)
5074 False
5075 >>> i = Int('i')
5076 >>> is_select(a[i])
5077 True
5078 """
5079 return is_app_of(a, Z3_OP_SELECT)
5080
5081

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

11310def is_seq(a):
11311 """Return `True` if `a` is a Z3 sequence expression.
11312 >>> print (is_seq(Unit(IntVal(0))))
11313 True
11314 >>> print (is_seq(StringVal("abc")))
11315 True
11316 """
11317 return isinstance(a, SeqRef)
11318
11319

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

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

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

5082def is_store(a):
5083 """Return `True` if `a` is a Z3 array store application.
5084
5085 >>> a = Array('a', IntSort(), IntSort())
5086 >>> is_store(a)
5087 False
5088 >>> is_store(Store(a, 0, 1))
5089 True
5090 """
5091 return is_app_of(a, Z3_OP_STORE)
5092

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

11320def is_string(a: Any) -> bool:
11321 """Return `True` if `a` is a Z3 string expression.
11322 >>> print (is_string(StringVal("ab")))
11323 True
11324 """
11325 return isinstance(a, SeqRef) and a.is_string()
11326
11327

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

11328def is_string_value(a: Any) -> bool:
11329 """return 'True' if 'a' is a Z3 string constant expression.
11330 >>> print (is_string_value(StringVal("a")))
11331 True
11332 >>> print (is_string_value(StringVal("a") + StringVal("b")))
11333 False
11334 """
11335 return isinstance(a, SeqRef) and a.is_string_value()
11336

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

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

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

3098def is_to_int(a : Any) -> bool:
3099 """Return `True` if `a` is an expression of the form ToInt(b).
3100
3101 >>> x = Real('x')
3102 >>> n = ToInt(x)
3103 >>> n
3104 ToInt(x)
3105 >>> is_to_int(n)
3106 True
3107 >>> is_to_int(x)
3108 False
3109 """
3110 return is_app_of(a, Z3_OP_TO_INT)
3111
3112

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

3083def is_to_real(a : Any) -> bool:
3084 """Return `True` if `a` is an expression of the form ToReal(b).
3085
3086 >>> x = Int('x')
3087 >>> n = ToReal(x)
3088 >>> n
3089 ToReal(x)
3090 >>> is_to_real(n)
3091 True
3092 >>> is_to_real(x)
3093 False
3094 """
3095 return is_app_of(a, Z3_OP_TO_REAL)
3096
3097

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

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

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

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

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

3556def IsInt(a):
3557 """ Return the Z3 predicate IsInt(a).
3558
3559 >>> x = Real('x')
3560 >>> IsInt(x + "1/2")
3561 IsInt(x + 1/2)
3562 >>> solve(IsInt(x + "1/2"), x > 0, x < 1)
3563 [x = 1/2]
3564 >>> solve(IsInt(x + "1/2"), x > 0, x < 1, x != "1/2")
3565 no solution
3566 """
3567 if z3_debug():
3568 _z3_assert(a.is_real(), "Z3 real expression expected.")
3569 ctx = a.ctx
3570 return BoolRef(Z3_mk_is_int(ctx.ref(), a.as_ast()), ctx)
3571
3572
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 5192 of file z3py.py.

5192def IsMember(e, s):
5193 """ Check if e is a member of set s
5194 >>> a = Const('a', SetSort(IntSort()))
5195 >>> IsMember(1, a)
5196 a[1]
5197 """
5198 ctx = _ctx_from_ast_arg_list([s, e])
5199 e = _py2expr(e, ctx)
5200 return BoolRef(Z3_mk_set_member(ctx.ref(), e.as_ast(), s.as_ast()), ctx)
5201
5202
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 5203 of file z3py.py.

5203def IsSubset(a, b):
5204 """ Check if a is a subset of b
5205 >>> a = Const('a', SetSort(IntSort()))
5206 >>> b = Const('b', SetSort(IntSort()))
5207 >>> IsSubset(a, b)
5208 subset(a, b)
5209 """
5210 ctx = _ctx_from_ast_arg_list([a, b])
5211 return BoolRef(Z3_mk_set_subset(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
5212
5213
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 5036 of file z3py.py.

5036def K(dom, v):
5037 """Return a Z3 constant array expression.
5038
5039 >>> a = K(IntSort(), 10)
5040 >>> a
5041 K(Int, 10)
5042 >>> a.sort()
5043 Array(Int, Int)
5044 >>> i = Int('i')
5045 >>> a[i]
5046 K(Int, 10)[i]
5047 >>> simplify(a[i])
5048 10
5049 """
5050 if z3_debug():
5051 _z3_assert(is_sort(dom), "Z3 sort expected")
5052 ctx = dom.ctx
5053 if not is_expr(v):
5054 v = _py2expr(v, ctx)
5055 return ArrayRef(Z3_mk_const_array(ctx.ref(), dom.ast, v.as_ast()), ctx)
5056
5057
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 2404 of file z3py.py.

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

11513def LastIndexOf(s, substr):
11514 """Retrieve the last index of substring within a string"""
11515 ctx = None
11516 ctx = _get_ctx2(s, substr, ctx)
11517 s = _coerce_seq(s, ctx)
11518 substr = _coerce_seq(substr, ctx)
11519 return ArithRef(Z3_mk_seq_last_index(s.ctx_ref(), s.as_ast(), substr.as_ast()), s.ctx)
11520
11521
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 11522 of file z3py.py.

11522def Length(s):
11523 """Obtain the length of a sequence 's'
11524 >>> l = Length(StringVal("abc"))
11525 >>> simplify(l)
11526 3
11527 """
11528 s = _coerce_seq(s)
11529 return ArithRef(Z3_mk_seq_length(s.ctx_ref(), s.as_ast()), s.ctx)
11530
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 11784 of file z3py.py.

11784def LinearOrder(a, index):
11785 return FuncDeclRef(Z3_mk_linear_order(a.ctx_ref(), a.ast, index), a.ctx)
11786
11787
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 11734 of file z3py.py.

11734def Loop(re, lo, hi=0):
11735 """Create the regular expression accepting between a lower and upper bound repetitions
11736 >>> re = Loop(Re("a"), 1, 3)
11737 >>> print(simplify(InRe("aa", re)))
11738 True
11739 >>> print(simplify(InRe("aaaa", re)))
11740 False
11741 >>> print(simplify(InRe("", re)))
11742 False
11743 """
11744 if z3_debug():
11745 _z3_assert(is_expr(re), "expression expected")
11746 return ReRef(Z3_mk_re_loop(re.ctx_ref(), re.as_ast(), lo, hi), re.ctx)
11747
11748
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 4489 of file z3py.py.

4489def LShR(a, b):
4490 """Create the Z3 expression logical right shift.
4491
4492 Use the operator >> for the arithmetical right shift.
4493
4494 >>> x, y = BitVecs('x y', 32)
4495 >>> LShR(x, y)
4496 LShR(x, y)
4497 >>> (x >> y).sexpr()
4498 '(bvashr x y)'
4499 >>> LShR(x, y).sexpr()
4500 '(bvlshr x y)'
4501 >>> BitVecVal(4, 3)
4502 4
4503 >>> BitVecVal(4, 3).as_signed_long()
4504 -4
4505 >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
4506 -2
4507 >>> simplify(BitVecVal(4, 3) >> 1)
4508 6
4509 >>> simplify(LShR(BitVecVal(4, 3), 1))
4510 2
4511 >>> simplify(BitVecVal(2, 3) >> 1)
4512 1
4513 >>> simplify(LShR(BitVecVal(2, 3), 1))
4514 1
4515 """
4516 _check_bv_args(a, b)
4517 a, b = _coerce_exprs(a, b)
4518 return BitVecRef(Z3_mk_bvlshr(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4519
4520
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 266 of file z3py.py.

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

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

5013def Map(f, *args):
5014 """Return a Z3 map array expression.
5015
5016 >>> f = Function('f', IntSort(), IntSort(), IntSort())
5017 >>> a1 = Array('a1', IntSort(), IntSort())
5018 >>> a2 = Array('a2', IntSort(), IntSort())
5019 >>> b = Map(f, a1, a2)
5020 >>> b
5021 Map(f, a1, a2)
5022 >>> prove(b[0] == f(a1[0], a2[0]))
5023 proved
5024 """
5025 args = _get_args(args)
5026 if z3_debug():
5027 _z3_assert(len(args) > 0, "At least one Z3 array expression expected")
5028 _z3_assert(is_func_decl(f), "First argument must be a Z3 function declaration")
5029 _z3_assert(all([is_array(a) for a in args]), "Z3 array expected expected")
5030 _z3_assert(len(args) == f.arity(), "Number of arguments mismatch")
5031 _args, sz = _to_ast_array(args)
5032 ctx = f.ctx
5033 return ArrayRef(Z3_mk_map(ctx.ref(), f.ast, sz, _args), ctx)
5034
5035
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 1967 of file z3py.py.

1967def mk_not(a):
1968 if is_not(a):
1969 return a.arg(0)
1970 else:
1971 return Not(a)
1972
1973

◆ Model()

Model (   ctx = None,
  eval = {} 
)

Definition at line 6948 of file z3py.py.

6948def Model(ctx=None, eval = {}):
6949 ctx = _get_ctx(ctx)
6950 mdl = ModelRef(Z3_mk_model(ctx.ref()), ctx)
6951 for k, v in eval.items():
6952 mdl.update_value(k, v)
6953 return mdl
6954
6955
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 2084 of file z3py.py.

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

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

11824def on_clause_eh(ctx, p, n, dep, clause):
11825 onc = _my_hacky_class
11826 p = _to_expr_ref(to_Ast(p), onc.ctx)
11827 clause = AstVector(to_AstVectorObj(clause), onc.ctx)
11828 deps = [dep[i] for i in range(n)]
11829 onc.on_clause(p, deps, clause)
11830

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

11699def Option(re):
11700 """Create the regular expression that optionally accepts the argument.
11701 >>> re = Option(Re("a"))
11702 >>> print(simplify(InRe("a", re)))
11703 True
11704 >>> print(simplify(InRe("", re)))
11705 True
11706 >>> print(simplify(InRe("aa", re)))
11707 False
11708 """
11709 if z3_debug():
11710 _z3_assert(is_expr(re), "expression expected")
11711 return ReRef(Z3_mk_re_option(re.ctx_ref(), re.as_ast()), re.ctx)
11712
11713
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 2015 of file z3py.py.

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

8733def OrElse(*ts, **ks):
8734 """Return a tactic that applies the tactics in `*ts` until one of them succeeds (it doesn't fail).
8735
8736 >>> x = Int('x')
8737 >>> t = OrElse(Tactic('split-clause'), Tactic('skip'))
8738 >>> # Tactic split-clause fails if there is no clause in the given goal.
8739 >>> t(x == 0)
8740 [[x == 0]]
8741 >>> t(Or(x == 0, x == 1))
8742 [[x == 0], [x == 1]]
8743 """
8744 if z3_debug():
8745 _z3_assert(len(ts) >= 2, "At least two arguments expected")
8746 ctx = ks.get("ctx", None)
8747 num = len(ts)
8748 r = ts[0]
8749 for i in range(num - 1):
8750 r = _or_else(r, ts[i + 1], ctx)
8751 return r
8752
8753

◆ ParAndThen()

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

Definition at line 8789 of file z3py.py.

8789def ParAndThen(t1, t2, ctx=None):
8790 """Alias for ParThen(t1, t2, ctx)."""
8791 return ParThen(t1, t2, ctx)
8792
8793

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

8754def ParOr(*ts, **ks):
8755 """Return a tactic that applies the tactics in `*ts` in parallel until one of them succeeds (it doesn't fail).
8756
8757 >>> x = Int('x')
8758 >>> t = ParOr(Tactic('simplify'), Tactic('fail'))
8759 >>> t(x + 1 == 2)
8760 [[x == 1]]
8761 """
8762 if z3_debug():
8763 _z3_assert(len(ts) >= 2, "At least two arguments expected")
8764 ctx = _get_ctx(ks.get("ctx", None))
8765 ts = [_to_tactic(t, ctx) for t in ts]
8766 sz = len(ts)
8767 _args = (TacticObj * sz)()
8768 for i in range(sz):
8769 _args[i] = ts[i].tactic
8770 return Tactic(Z3_tactic_par_or(ctx.ref(), sz, _args), ctx)
8771
8772
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 9669 of file z3py.py.

9669def parse_smt2_file(f, sorts={}, decls={}, ctx=None):
9670 """Parse a file in SMT 2.0 format using the given sorts and decls.
9671
9672 This function is similar to parse_smt2_string().
9673 """
9674 ctx = _get_ctx(ctx)
9675 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
9676 dsz, dnames, ddecls = _dict2darray(decls, ctx)
9677 return AstVector(Z3_parse_smtlib2_file(ctx.ref(), f, ssz, snames, ssorts, dsz, dnames, ddecls), ctx)
9678
9679
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 9648 of file z3py.py.

9648def parse_smt2_string(s, sorts={}, decls={}, ctx=None):
9649 """Parse a string in SMT 2.0 format using the given sorts and decls.
9650
9651 The arguments sorts and decls are Python dictionaries used to initialize
9652 the symbol table used for the SMT 2.0 parser.
9653
9654 >>> parse_smt2_string('(declare-const x Int) (assert (> x 0)) (assert (< x 10))')
9655 [x > 0, x < 10]
9656 >>> x, y = Ints('x y')
9657 >>> f = Function('f', IntSort(), IntSort())
9658 >>> parse_smt2_string('(assert (> (+ foo (g bar)) 0))', decls={ 'foo' : x, 'bar' : y, 'g' : f})
9659 [x + f(y) > 0]
9660 >>> parse_smt2_string('(declare-const a U) (assert (> a 0))', sorts={ 'U' : IntSort() })
9661 [a > 0]
9662 """
9663 ctx = _get_ctx(ctx)
9664 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
9665 dsz, dnames, ddecls = _dict2darray(decls, ctx)
9666 return AstVector(Z3_parse_smtlib2_string(ctx.ref(), s, ssz, snames, ssorts, dsz, dnames, ddecls), ctx)
9667
9668
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 8773 of file z3py.py.

8773def ParThen(t1, t2, ctx=None):
8774 """Return a tactic that applies t1 and then t2 to every subgoal produced by t1.
8775 The subgoals are processed in parallel.
8776
8777 >>> x, y = Ints('x y')
8778 >>> t = ParThen(Tactic('split-clause'), Tactic('propagate-values'))
8779 >>> t(And(Or(x == 1, x == 2), y == x + 1))
8780 [[x == 1, y == 2], [x == 2, y == 3]]
8781 """
8782 t1 = _to_tactic(t1, ctx)
8783 t2 = _to_tactic(t2, ctx)
8784 if z3_debug():
8785 _z3_assert(t1.ctx == t2.ctx, "Context mismatch")
8786 return Tactic(Z3_tactic_par_and_then(t1.ctx.ref(), t1.tactic, t2.tactic), t1.ctx)
8787
8788
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 11780 of file z3py.py.

11780def PartialOrder(a, index):
11781 return FuncDeclRef(Z3_mk_partial_order(a.ctx_ref(), a.ast, index), a.ctx)
11782
11783
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 9425 of file z3py.py.

9425def PbEq(args, k, ctx=None):
9426 """Create a Pseudo-Boolean equality k constraint.
9427
9428 >>> a, b, c = Bools('a b c')
9429 >>> f = PbEq(((a,1),(b,3),(c,2)), 3)
9430 """
9431 _z3_check_cint_overflow(k, "k")
9432 ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
9433 return BoolRef(Z3_mk_pbeq(ctx.ref(), sz, _args, _coeffs, k), ctx)
9434
9435
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 9414 of file z3py.py.

9414def PbGe(args, k):
9415 """Create a Pseudo-Boolean inequality k constraint.
9416
9417 >>> a, b, c = Bools('a b c')
9418 >>> f = PbGe(((a,1),(b,3),(c,2)), 3)
9419 """
9420 _z3_check_cint_overflow(k, "k")
9421 ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
9422 return BoolRef(Z3_mk_pbge(ctx.ref(), sz, _args, _coeffs, k), ctx)
9423
9424
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 9403 of file z3py.py.

9403def PbLe(args, k):
9404 """Create a Pseudo-Boolean inequality k constraint.
9405
9406 >>> a, b, c = Bools('a b c')
9407 >>> f = PbLe(((a,1),(b,3),(c,2)), 3)
9408 """
9409 _z3_check_cint_overflow(k, "k")
9410 ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
9411 return BoolRef(Z3_mk_pble(ctx.ref(), sz, _args, _coeffs, k), ctx)
9412
9413
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 11792 of file z3py.py.

11792def PiecewiseLinearOrder(a, index):
11793 return FuncDeclRef(Z3_mk_piecewise_linear_order(a.ctx_ref(), a.ast, index), a.ctx)
11794
11795
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 11684 of file z3py.py.

11684def Plus(re):
11685 """Create the regular expression accepting one or more repetitions of argument.
11686 >>> re = Plus(Re("a"))
11687 >>> print(simplify(InRe("aa", re)))
11688 True
11689 >>> print(simplify(InRe("ab", re)))
11690 False
11691 >>> print(simplify(InRe("", re)))
11692 False
11693 """
11694 if z3_debug():
11695 _z3_assert(is_expr(re), "expression expected")
11696 return ReRef(Z3_mk_re_plus(re.ctx_ref(), re.as_ast()), re.ctx)
11697
11698
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 11429 of file z3py.py.

11429def PrefixOf(a, b):
11430 """Check if 'a' is a prefix of 'b'
11431 >>> s1 = PrefixOf("ab", "abc")
11432 >>> simplify(s1)
11433 True
11434 >>> s2 = PrefixOf("bc", "abc")
11435 >>> simplify(s2)
11436 False
11437 """
11438 ctx = _get_ctx2(a, b)
11439 a = _coerce_seq(a, ctx)
11440 b = _coerce_seq(b, ctx)
11441 return BoolRef(Z3_mk_seq_prefix(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
11442
11443
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 9069 of file z3py.py.

9069def probe_description(name, ctx=None):
9070 """Return a short description for the probe named `name`.
9071
9072 >>> d = probe_description('memory')
9073 """
9074 ctx = _get_ctx(ctx)
9075 return Z3_probe_get_descr(ctx.ref(), name)
9076
9077
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 9058 of file z3py.py.

9058def probes(ctx=None):
9059 """Return a list of all available probes in Z3.
9060
9061 >>> l = probes()
9062 >>> l.count('memory') == 1
9063 True
9064 """
9065 ctx = _get_ctx(ctx)
9066 return [Z3_get_probe_name(ctx.ref(), i) for i in range(Z3_get_num_probes(ctx.ref()))]
9067
9068
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 9310 of file z3py.py.

9310def Product(*args):
9311 """Create the product of the Z3 expressions.
9312
9313 >>> a, b, c = Ints('a b c')
9314 >>> Product(a, b, c)
9315 a*b*c
9316 >>> Product([a, b, c])
9317 a*b*c
9318 >>> A = IntVector('a', 5)
9319 >>> Product(A)
9320 a__0*a__1*a__2*a__3*a__4
9321 """
9322 args = _get_args(args)
9323 if len(args) == 0:
9324 return 1
9325 ctx = _ctx_from_ast_arg_list(args)
9326 if ctx is None:
9327 return _reduce(lambda a, b: a * b, args, 1)
9328 args = _coerce_expr_list(args, ctx)
9329 if is_bv(args[0]):
9330 return _reduce(lambda a, b: a * b, args, 1)
9331 else:
9332 _args, sz = _to_ast_array(args)
9333 return ArithRef(Z3_mk_mul(ctx.ref(), sz, _args), ctx)
9334
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 11989 of file z3py.py.

11989def PropagateFunction(name, *sig):
11990 """Create a function that gets tracked by user propagator.
11991 Every term headed by this function symbol is tracked.
11992 If a term is fixed and the fixed callback is registered a
11993 callback is invoked that the term headed by this function is fixed.
11994 """
11995 sig = _get_args(sig)
11996 if z3_debug():
11997 _z3_assert(len(sig) > 0, "At least two arguments expected")
11998 arity = len(sig) - 1
11999 rng = sig[arity]
12000 if z3_debug():
12001 _z3_assert(is_sort(rng), "Z3 sort expected")
12002 dom = (Sort * arity)()
12003 for i in range(arity):
12004 if z3_debug():
12005 _z3_assert(is_sort(sig[i]), "Z3 sort expected")
12006 dom[i] = sig[i].ast
12007 ctx = rng.ctx
12008 return FuncDeclRef(Z3_solver_propagate_declare(ctx.ref(), to_symbol(name, ctx), arity, dom, rng.ast), ctx)
12009
12010
12011
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 9497 of file z3py.py.

9497def prove(claim, show=False, **keywords):
9498 """Try to prove the given claim.
9499
9500 This is a simple function for creating demonstrations. It tries to prove
9501 `claim` by showing the negation is unsatisfiable.
9502
9503 >>> p, q = Bools('p q')
9504 >>> prove(Not(And(p, q)) == Or(Not(p), Not(q)))
9505 proved
9506 """
9507 if z3_debug():
9508 _z3_assert(is_bool(claim), "Z3 Boolean expression expected")
9509 s = Solver()
9510 s.set(**keywords)
9511 s.add(Not(claim))
9512 if show:
9513 print(s)
9514 r = s.check()
9515 if r == unsat:
9516 print("proved")
9517 elif r == unknown:
9518 print("failed to prove")
9519 print(s.model())
9520 else:
9521 print("counterexample")
9522 print(s.model())
9523
9524

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

3395def Q(a, b, ctx=None):
3396 """Return a Z3 rational a/b.
3397
3398 If `ctx=None`, then the global context is used.
3399
3400 >>> Q(3,5)
3401 3/5
3402 >>> Q(3,5).sort()
3403 Real
3404 """
3405 return simplify(RatVal(a, b, ctx=ctx))
3406
3407

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

11749def Range(lo, hi, ctx=None):
11750 """Create the range regular expression over two sequences of length 1
11751 >>> range = Range("a","z")
11752 >>> print(simplify(InRe("b", range)))
11753 True
11754 >>> print(simplify(InRe("bb", range)))
11755 False
11756 """
11757 lo = _coerce_seq(lo, ctx)
11758 hi = _coerce_seq(hi, ctx)
11759 if z3_debug():
11760 _z3_assert(is_expr(lo), "expression expected")
11761 _z3_assert(is_expr(hi), "expression expected")
11762 return ReRef(Z3_mk_re_range(lo.ctx_ref(), lo.ast, hi.ast), lo.ctx)
11763
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.

Note: Division by zero (b == 0) is allowed in Z3 symbolic expressions.
Z3 can reason about such expressions symbolically.

>>> RatVal(3,5)
3/5
>>> RatVal(3,5).sort()
Real

Definition at line 3375 of file z3py.py.

3375def RatVal(a, b, ctx=None):
3376 """Return a Z3 rational a/b.
3377
3378 If `ctx=None`, then the global context is used.
3379
3380 Note: Division by zero (b == 0) is allowed in Z3 symbolic expressions.
3381 Z3 can reason about such expressions symbolically.
3382
3383 >>> RatVal(3,5)
3384 3/5
3385 >>> RatVal(3,5).sort()
3386 Real
3387 """
3388 if z3_debug():
3389 _z3_assert(_is_int(a) or isinstance(a, str), "First argument cannot be converted into an integer")
3390 _z3_assert(_is_int(b) or isinstance(b, str), "Second argument cannot be converted into an integer")
3391 # Division by 0 is intentionally allowed - Z3 handles it symbolically
3392 return simplify(RealVal(a, ctx) / RealVal(b, ctx))
3393
3394

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

11593def Re(s, ctx=None):
11594 """The regular expression that accepts sequence 's'
11595 >>> s1 = Re("ab")
11596 >>> s2 = Re(StringVal("ab"))
11597 >>> s3 = Re(Unit(BoolVal(True)))
11598 """
11599 s = _coerce_seq(s, ctx)
11600 return ReRef(Z3_mk_seq_to_re(s.ctx_ref(), s.as_ast()), s.ctx)
11601
11602
11603# Regular expressions
11604
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 3461 of file z3py.py.

3461def Real(name, ctx=None):
3462 """Return a real constant named `name`. If `ctx=None`, then the global context is used.
3463
3464 >>> x = Real('x')
3465 >>> is_real(x)
3466 True
3467 >>> is_real(x + 1)
3468 True
3469 """
3470 ctx = _get_ctx(ctx)
3471 return ArithRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), RealSort(ctx).ast), ctx)
3472
3473

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

3474def Reals(names, ctx=None):
3475 """Return a tuple of real constants.
3476
3477 >>> x, y, z = Reals('x y z')
3478 >>> Sum(x, y, z)
3479 x + y + z
3480 >>> Sum(x, y, z).sort()
3481 Real
3482 """
3483 ctx = _get_ctx(ctx)
3484 if isinstance(names, str):
3485 names = names.split(" ")
3486 return [Real(name, ctx) for name in names]
3487
3488

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

3315def RealSort(ctx=None):
3316 """Return the real sort in the given context. If `ctx=None`, then the global context is used.
3317
3318 >>> RealSort()
3319 Real
3320 >>> x = Const('x', RealSort())
3321 >>> is_real(x)
3322 True
3323 >>> is_int(x)
3324 False
3325 >>> x.sort() == RealSort()
3326 True
3327 """
3328 ctx = _get_ctx(ctx)
3329 return ArithSortRef(Z3_mk_real_sort(ctx.ref()), ctx)
3330
3331
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 3356 of file z3py.py.

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

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

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

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

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

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

3489def RealVector(prefix, sz, ctx=None):
3490 """Return a list of real constants of size `sz`.
3491
3492 >>> X = RealVector('x', 3)
3493 >>> X
3494 [x__0, x__1, x__2]
3495 >>> Sum(X)
3496 x__0 + x__1 + x__2
3497 >>> Sum(X).sort()
3498 Real
3499 """
3500 ctx = _get_ctx(ctx)
3501 return [Real("%s__%s" % (prefix, i), ctx) for i in range(sz)]
3502
3503

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

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

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

8822def Repeat(t, max=4294967295, ctx=None):
8823 """Return a tactic that keeps applying `t` until the goal is not modified anymore
8824 or the maximum number of iterations `max` is reached.
8825
8826 >>> x, y = Ints('x y')
8827 >>> c = And(Or(x == 0, x == 1), Or(y == 0, y == 1), x > y)
8828 >>> t = Repeat(OrElse(Tactic('split-clause'), Tactic('skip')))
8829 >>> r = t(c)
8830 >>> for subgoal in r: print(subgoal)
8831 [x == 0, y == 0, x > y]
8832 [x == 0, y == 1, x > y]
8833 [x == 1, y == 0, x > y]
8834 [x == 1, y == 1, x > y]
8835 >>> t = Then(t, Tactic('propagate-values'))
8836 >>> t(c)
8837 [[x == 1, y == 0]]
8838 """
8839 t = _to_tactic(t, ctx)
8840 return Tactic(Z3_tactic_repeat(t.ctx.ref(), t.tactic, max), t.ctx)
8841
8842
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 4611 of file z3py.py.

4611def RepeatBitVec(n, a):
4612 """Return an expression representing `n` copies of `a`.
4613
4614 >>> x = BitVec('x', 8)
4615 >>> n = RepeatBitVec(4, x)
4616 >>> n
4617 RepeatBitVec(4, x)
4618 >>> n.size()
4619 32
4620 >>> v0 = BitVecVal(10, 4)
4621 >>> print("%.x" % v0.as_long())
4622 a
4623 >>> v = simplify(RepeatBitVec(4, v0))
4624 >>> v.size()
4625 16
4626 >>> print("%.x" % v.as_long())
4627 aaaa
4628 """
4629 if z3_debug():
4630 _z3_assert(_is_int(n), "First argument must be an integer")
4631 _z3_assert(is_bv(a), "Second argument must be a Z3 bit-vector expression")
4632 return BitVecRef(Z3_mk_repeat(a.ctx_ref(), n, a.as_ast()), a.ctx)
4633
4634
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 11478 of file z3py.py.

11478def Replace(s, src, dst):
11479 """Replace the first occurrence of 'src' by 'dst' in 's'
11480 >>> r = Replace("aaa", "a", "b")
11481 >>> simplify(r)
11482 "baa"
11483 """
11484 ctx = _get_ctx2(dst, s)
11485 if ctx is None and is_expr(src):
11486 ctx = src.ctx
11487 src = _coerce_seq(src, ctx)
11488 dst = _coerce_seq(dst, ctx)
11489 s = _coerce_seq(s, ctx)
11490 return SeqRef(Z3_mk_seq_replace(src.ctx_ref(), s.as_ast(), src.as_ast(), dst.as_ast()), s.ctx)
11491
11492
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 322 of file z3py.py.

322def reset_params() -> None:
323 """Reset all global (or module) parameters.
324 """
326
327
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 11612 of file z3py.py.

11612def ReSort(s):
11613 if is_ast(s):
11614 return ReSortRef(Z3_mk_re_sort(s.ctx.ref(), s.ast), s.ctx)
11615 if s is None or isinstance(s, Context):
11616 ctx = _get_ctx(s)
11617 return ReSortRef(Z3_mk_re_sort(ctx.ref(), Z3_mk_string_sort(ctx.ref())), s.ctx)
11618 raise Z3Exception("Regular expression sort constructor expects either a string or a context or no argument")
11619
11620
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 10084 of file z3py.py.

10084def RNA(ctx=None):
10085 ctx = _get_ctx(ctx)
10086 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_away(ctx.ref()), ctx)
10087
10088
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 10074 of file z3py.py.

10074def RNE(ctx=None):
10075 ctx = _get_ctx(ctx)
10076 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_even(ctx.ref()), ctx)
10077
10078
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 4521 of file z3py.py.

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

4537def RotateRight(a, b):
4538 """Return an expression representing `a` rotated to the right `b` times.
4539
4540 >>> a, b = BitVecs('a b', 16)
4541 >>> RotateRight(a, b)
4542 RotateRight(a, b)
4543 >>> simplify(RotateRight(a, 0))
4544 a
4545 >>> simplify(RotateRight(a, 16))
4546 a
4547 """
4548 _check_bv_args(a, b)
4549 a, b = _coerce_exprs(a, b)
4550 return BitVecRef(Z3_mk_ext_rotate_right(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4551
4552
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 10079 of file z3py.py.

10079def RoundNearestTiesToAway(ctx=None):
10080 ctx = _get_ctx(ctx)
10081 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_away(ctx.ref()), ctx)
10082
10083

◆ RoundNearestTiesToEven()

RoundNearestTiesToEven (   ctx = None)

Definition at line 10069 of file z3py.py.

10069def RoundNearestTiesToEven(ctx=None):
10070 ctx = _get_ctx(ctx)
10071 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_even(ctx.ref()), ctx)
10072
10073

◆ RoundTowardNegative()

RoundTowardNegative (   ctx = None)

Definition at line 10099 of file z3py.py.

10099def RoundTowardNegative(ctx=None):
10100 ctx = _get_ctx(ctx)
10101 return FPRMRef(Z3_mk_fpa_round_toward_negative(ctx.ref()), ctx)
10102
10103
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 10089 of file z3py.py.

10089def RoundTowardPositive(ctx=None):
10090 ctx = _get_ctx(ctx)
10091 return FPRMRef(Z3_mk_fpa_round_toward_positive(ctx.ref()), ctx)
10092
10093
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 10109 of file z3py.py.

10109def RoundTowardZero(ctx=None):
10110 ctx = _get_ctx(ctx)
10111 return FPRMRef(Z3_mk_fpa_round_toward_zero(ctx.ref()), ctx)
10112
10113
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 10104 of file z3py.py.

10104def RTN(ctx=None):
10105 ctx = _get_ctx(ctx)
10106 return FPRMRef(Z3_mk_fpa_round_toward_negative(ctx.ref()), ctx)
10107
10108

◆ RTP()

RTP (   ctx = None)

Definition at line 10094 of file z3py.py.

10094def RTP(ctx=None):
10095 ctx = _get_ctx(ctx)
10096 return FPRMRef(Z3_mk_fpa_round_toward_positive(ctx.ref()), ctx)
10097
10098

◆ RTZ()

RTZ (   ctx = None)

Definition at line 10114 of file z3py.py.

10114def RTZ(ctx=None):
10115 ctx = _get_ctx(ctx)
10116 return FPRMRef(Z3_mk_fpa_round_toward_zero(ctx.ref()), ctx)
10117
10118

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

4997def Select(a, *args):
4998 """Return a Z3 select array expression.
4999
5000 >>> a = Array('a', IntSort(), IntSort())
5001 >>> i = Int('i')
5002 >>> Select(a, i)
5003 a[i]
5004 >>> eq(Select(a, i), a[i])
5005 True
5006 """
5007 args = _get_args(args)
5008 if z3_debug():
5009 _z3_assert(is_array_sort(a), "First argument must be a Z3 array expression")
5010 return a[args]
5011
5012

◆ SeqFoldLeft()

SeqFoldLeft (   f,
  a,
  s 
)

Definition at line 11545 of file z3py.py.

11545def SeqFoldLeft(f, a, s):
11546 ctx = _get_ctx2(f, s)
11547 s = _coerce_seq(s, ctx)
11548 a = _py2expr(a)
11549 return _to_expr_ref(Z3_mk_seq_foldl(s.ctx_ref(), f.as_ast(), a.as_ast(), s.as_ast()), ctx)
11550
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 11551 of file z3py.py.

11551def SeqFoldLeftI(f, i, a, s):
11552 ctx = _get_ctx2(f, s)
11553 s = _coerce_seq(s, ctx)
11554 a = _py2expr(a)
11555 i = _py2expr(i)
11556 return _to_expr_ref(Z3_mk_seq_foldli(s.ctx_ref(), f.as_ast(), i.as_ast(), a.as_ast(), s.as_ast()), ctx)
11557
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 11531 of file z3py.py.

11531def SeqMap(f, s):
11532 """Map function 'f' over sequence 's'"""
11533 ctx = _get_ctx2(f, s)
11534 s = _coerce_seq(s, ctx)
11535 return _to_expr_ref(Z3_mk_seq_map(s.ctx_ref(), f.as_ast(), s.as_ast()), ctx)
11536
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 11537 of file z3py.py.

11537def SeqMapI(f, i, s):
11538 """Map function 'f' over sequence 's' at index 'i'"""
11539 ctx = _get_ctx2(f, s)
11540 s = _coerce_seq(s, ctx)
11541 if not is_expr(i):
11542 i = _py2expr(i)
11543 return _to_expr_ref(Z3_mk_seq_mapi(s.ctx_ref(), f.as_ast(), i.as_ast(), s.as_ast()), ctx)
11544
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 11178 of file z3py.py.

11178def SeqSort(s):
11179 """Create a sequence sort over elements provided in the argument
11180 >>> s = SeqSort(IntSort())
11181 >>> s == Unit(IntVal(1)).sort()
11182 True
11183 """
11184 return SeqSortRef(Z3_mk_seq_sort(s.ctx_ref(), s.ast), s.ctx)
11185
11186
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 9730 of file z3py.py.

9730def set_default_fp_sort(ebits, sbits, ctx=None):
9731 global _dflt_fpsort_ebits
9732 global _dflt_fpsort_sbits
9733 _dflt_fpsort_ebits = ebits
9734 _dflt_fpsort_sbits = sbits
9735
9736

◆ set_default_rounding_mode()

set_default_rounding_mode (   rm,
  ctx = None 
)

Definition at line 9717 of file z3py.py.

9717def set_default_rounding_mode(rm, ctx=None):
9718 global _dflt_rounding_mode
9719 if is_fprm_value(rm):
9720 _dflt_rounding_mode = rm.kind()
9721 else:
9722 _z3_assert(_dflt_rounding_mode in _ROUNDING_MODES, "illegal rounding mode")
9723 _dflt_rounding_mode = rm
9724
9725

◆ set_option()

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

Definition at line 328 of file z3py.py.

328def set_option(*args, **kws):
329 """Alias for 'set_param' for backward compatibility.
330 """
331 return set_param(*args, **kws)
332
333

◆ set_param()

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

>>> set_param(precision=10)

Definition at line 298 of file z3py.py.

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

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

5171def SetComplement(s):
5172 """ The complement of set s
5173 >>> a = Const('a', SetSort(IntSort()))
5174 >>> SetComplement(a)
5175 complement(a)
5176 """
5177 ctx = s.ctx
5178 return ArrayRef(Z3_mk_set_complement(ctx.ref(), s.as_ast()), ctx)
5179
5180
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 5160 of file z3py.py.

5160def SetDel(s, e):
5161 """ Remove element e to set s
5162 >>> a = Const('a', SetSort(IntSort()))
5163 >>> SetDel(a, 1)
5164 Store(a, 1, False)
5165 """
5166 ctx = _ctx_from_ast_arg_list([s, e])
5167 e = _py2expr(e, ctx)
5168 return ArrayRef(Z3_mk_set_del(ctx.ref(), s.as_ast(), e.as_ast()), ctx)
5169
5170
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 5181 of file z3py.py.

5181def SetDifference(a, b):
5182 """ The set difference of a and b
5183 >>> a = Const('a', SetSort(IntSort()))
5184 >>> b = Const('b', SetSort(IntSort()))
5185 >>> SetDifference(a, b)
5186 setminus(a, b)
5187 """
5188 ctx = _ctx_from_ast_arg_list([a, b])
5189 return ArrayRef(Z3_mk_set_difference(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
5190
5191
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 5136 of file z3py.py.

5136def SetIntersect(*args):
5137 """ Take the union of sets
5138 >>> a = Const('a', SetSort(IntSort()))
5139 >>> b = Const('b', SetSort(IntSort()))
5140 >>> SetIntersect(a, b)
5141 intersection(a, b)
5142 """
5143 args = _get_args(args)
5144 ctx = _ctx_from_ast_arg_list(args)
5145 _args, sz = _to_ast_array(args)
5146 return ArrayRef(Z3_mk_set_intersect(ctx.ref(), sz, _args), ctx)
5147
5148
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 5100 of file z3py.py.

5100def SetSort(s):
5101 """ Create a set sort over element sort s"""
5102 return ArraySort(s, BoolSort())
5103
5104

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

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

4553def SignExt(n, a):
4554 """Return a bit-vector expression with `n` extra sign-bits.
4555
4556 >>> x = BitVec('x', 16)
4557 >>> n = SignExt(8, x)
4558 >>> n.size()
4559 24
4560 >>> n
4561 SignExt(8, x)
4562 >>> n.sort()
4563 BitVec(24)
4564 >>> v0 = BitVecVal(2, 2)
4565 >>> v0
4566 2
4567 >>> v0.size()
4568 2
4569 >>> v = simplify(SignExt(6, v0))
4570 >>> v
4571 254
4572 >>> v.size()
4573 8
4574 >>> print("%.x" % v.as_long())
4575 fe
4576 """
4577 if z3_debug():
4578 _z3_assert(_is_int(n), "First argument must be an integer")
4579 _z3_assert(is_bv(a), "Second argument must be a Z3 bit-vector expression")
4580 return BitVecRef(Z3_mk_sign_ext(a.ctx_ref(), n, a.as_ast()), a.ctx)
4581
4582
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 7747 of file z3py.py.

7747def SimpleSolver(ctx=None, logFile=None):
7748 """Return a simple general purpose solver with limited amount of preprocessing.
7749
7750 >>> s = SimpleSolver()
7751 >>> x = Int('x')
7752 >>> s.add(x > 0)
7753 >>> s.check()
7754 sat
7755 """
7756 ctx = _get_ctx(ctx)
7757 return Solver(Z3_mk_simple_solver(ctx.ref()), ctx, logFile)
7758
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 9174 of file z3py.py.

9174def simplify(a, *arguments, **keywords):
9175 """Simplify the expression `a` using the given options.
9176
9177 This function has many options. Use `help_simplify` to obtain the complete list.
9178
9179 >>> x = Int('x')
9180 >>> y = Int('y')
9181 >>> simplify(x + 1 + y + x + 1)
9182 2 + 2*x + y
9183 >>> simplify((x + 1)*(y + 1), som=True)
9184 1 + x + y + x*y
9185 >>> simplify(Distinct(x, y, 1), blast_distinct=True)
9186 And(Not(x == y), Not(x == 1), Not(y == 1))
9187 >>> simplify(And(x == 0, y == 1), elim_and=True)
9188 Not(Or(Not(x == 0), Not(y == 1)))
9189 """
9190 if z3_debug():
9191 _z3_assert(is_expr(a), "Z3 expression expected")
9192 if len(arguments) > 0 or len(keywords) > 0:
9193 p = args2params(arguments, keywords, a.ctx)
9194 return _to_expr_ref(Z3_simplify_ex(a.ctx_ref(), a.as_ast(), p.params), a.ctx)
9195 else:
9196 return _to_expr_ref(Z3_simplify(a.ctx_ref(), a.as_ast()), a.ctx)
9197
9198
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 9204 of file z3py.py.

9204def simplify_param_descrs():
9205 """Return the set of parameter descriptions for Z3 `simplify` procedure."""
9206 return ParamDescrsRef(Z3_simplify_get_param_descrs(main_ctx().ref()), main_ctx())
9207
9208
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 9436 of file z3py.py.

9436def solve(*args, **keywords):
9437 """Solve the constraints `*args`.
9438
9439 This is a simple function for creating demonstrations. It creates a solver,
9440 configure it using the options in `keywords`, adds the constraints
9441 in `args`, and invokes check.
9442
9443 >>> a = Int('a')
9444 >>> solve(a > 0, a < 2)
9445 [a = 1]
9446 """
9447 show = keywords.pop("show", False)
9448 s = Solver()
9449 s.set(**keywords)
9450 s.add(*args)
9451 if show:
9452 print(s)
9453 r = s.check()
9454 if r == unsat:
9455 print("no solution")
9456 elif r == unknown:
9457 print("failed to solve")
9458 try:
9459 print(s.model())
9460 except Z3Exception:
9461 return
9462 else:
9463 print(s.model())
9464
9465

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

9466def solve_using(s, *args, **keywords):
9467 """Solve the constraints `*args` using solver `s`.
9468
9469 This is a simple function for creating demonstrations. It is similar to `solve`,
9470 but it uses the given solver `s`.
9471 It configures solver `s` using the options in `keywords`, adds the constraints
9472 in `args`, and invokes check.
9473 """
9474 show = keywords.pop("show", False)
9475 if z3_debug():
9476 _z3_assert(isinstance(s, Solver), "Solver object expected")
9477 s.set(**keywords)
9478 s.add(*args)
9479 if show:
9480 print("Problem:")
9481 print(s)
9482 r = s.check()
9483 if r == unsat:
9484 print("no solution")
9485 elif r == unknown:
9486 print("failed to solve")
9487 try:
9488 print(s.model())
9489 except Z3Exception:
9490 return
9491 else:
9492 if show:
9493 print("Solution:")
9494 print(s.model())
9495
9496

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

7726def SolverFor(logic, ctx=None, logFile=None):
7727 """Create a solver customized for the given logic.
7728
7729 The parameter `logic` is a string. It should be contains
7730 the name of a SMT-LIB logic.
7731 See http://www.smtlib.org/ for the name of all available logics.
7732
7733 >>> s = SolverFor("QF_LIA")
7734 >>> x = Int('x')
7735 >>> s.add(x > 0)
7736 >>> s.add(x < 2)
7737 >>> s.check()
7738 sat
7739 >>> s.model()
7740 [x = 1]
7741 """
7742 ctx = _get_ctx(ctx)
7743 logic = to_symbol(logic)
7744 return Solver(Z3_mk_solver_for_logic(ctx.ref(), logic), ctx, logFile)
7745
7746
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 3573 of file z3py.py.

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

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

4468def SRem(a, b):
4469 """Create the Z3 expression signed remainder.
4470
4471 Use the operator % for signed modulus, and URem() for unsigned remainder.
4472
4473 >>> x = BitVec('x', 32)
4474 >>> y = BitVec('y', 32)
4475 >>> SRem(x, y)
4476 SRem(x, y)
4477 >>> SRem(x, y).sort()
4478 BitVec(32)
4479 >>> (x % y).sexpr()
4480 '(bvsmod x y)'
4481 >>> SRem(x, y).sexpr()
4482 '(bvsrem x y)'
4483 """
4484 _check_bv_args(a, b)
4485 a, b = _coerce_exprs(a, b)
4486 return BitVecRef(Z3_mk_bvsrem(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4487
4488
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 11719 of file z3py.py.

11719def Star(re):
11720 """Create the regular expression accepting zero or more repetitions of argument.
11721 >>> re = Star(Re("a"))
11722 >>> print(simplify(InRe("aa", re)))
11723 True
11724 >>> print(simplify(InRe("ab", re)))
11725 False
11726 >>> print(simplify(InRe("", re)))
11727 True
11728 """
11729 if z3_debug():
11730 _z3_assert(is_expr(re), "expression expected")
11731 return ReRef(Z3_mk_re_star(re.ctx_ref(), re.as_ast()), re.ctx)
11732
11733
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 4980 of file z3py.py.

4980def Store(a, *args):
4981 """Return a Z3 store array expression.
4982
4983 >>> a = Array('a', IntSort(), IntSort())
4984 >>> i, v = Ints('i v')
4985 >>> s = Store(a, i, v)
4986 >>> s.sort()
4987 Array(Int, Int)
4988 >>> prove(s[i] == v)
4989 proved
4990 >>> j = Int('j')
4991 >>> prove(Implies(i != j, s[j] == a[j]))
4992 proved
4993 """
4994 return Update(a, args)
4995
4996

Referenced by ModelRef.get_interp().

◆ StrFromCode()

StrFromCode (   c)
Convert code to a string

Definition at line 11587 of file z3py.py.

11587def StrFromCode(c):
11588 """Convert code to a string"""
11589 if not is_expr(c):
11590 c = _py2expr(c)
11591 return SeqRef(Z3_mk_string_from_code(c.ctx_ref(), c.as_ast()), c.ctx)
11592
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 11344 of file z3py.py.

11344def String(name, ctx=None):
11345 """Return a string constant named `name`. If `ctx=None`, then the global context is used.
11346
11347 >>> x = String('x')
11348 """
11349 ctx = _get_ctx(ctx)
11350 return SeqRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), StringSort(ctx).ast), ctx)
11351
11352

◆ Strings()

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

Definition at line 11353 of file z3py.py.

11353def Strings(names, ctx=None):
11354 """Return a tuple of String constants. """
11355 ctx = _get_ctx(ctx)
11356 if isinstance(names, str):
11357 names = names.split(" ")
11358 return [String(name, ctx) for name in names]
11359
11360

◆ StringSort()

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

Definition at line 11159 of file z3py.py.

11159def StringSort(ctx=None):
11160 """Create a string sort
11161 >>> s = StringSort()
11162 >>> print(s)
11163 String
11164 """
11165 ctx = _get_ctx(ctx)
11166 return SeqSortRef(Z3_mk_string_sort(ctx.ref()), ctx)
11167

◆ StringVal()

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

Definition at line 11337 of file z3py.py.

11337def StringVal(s, ctx=None):
11338 """create a string expression"""
11339 s = "".join(str(ch) if 32 <= ord(ch) and ord(ch) < 127 else "\\u{%x}" % (ord(ch)) for ch in s)
11340 ctx = _get_ctx(ctx)
11341 return SeqRef(Z3_mk_string(ctx.ref(), s), ctx)
11342
11343
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 11581 of file z3py.py.

11581def StrToCode(s):
11582 """Convert a unit length string to integer code"""
11583 if not is_expr(s):
11584 s = _py2expr(s)
11585 return ArithRef(Z3_mk_string_to_code(s.ctx_ref(), s.as_ast()), s.ctx)
11586
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 11558 of file z3py.py.

11558def StrToInt(s):
11559 """Convert string expression to integer
11560 >>> a = StrToInt("1")
11561 >>> simplify(1 == a)
11562 True
11563 >>> b = StrToInt("2")
11564 >>> simplify(1 == b)
11565 False
11566 >>> c = StrToInt(IntToStr(2))
11567 >>> simplify(1 == c)
11568 False
11569 """
11570 s = _coerce_seq(s)
11571 return ArithRef(Z3_mk_str_to_int(s.ctx_ref(), s.as_ast()), s.ctx)
11572
11573
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 11375 of file z3py.py.

11375def SubSeq(s, offset, length):
11376 """Extract substring or subsequence starting at offset.
11377
11378 This is a convenience function that redirects to Extract(s, offset, length).
11379
11380 >>> s = StringVal("hello world")
11381 >>> SubSeq(s, 0, 5) # Extract "hello"
11382 str.substr("hello world", 0, 5)
11383 >>> simplify(SubSeq(StringVal("testing"), 2, 4))
11384 "stin"
11385 """
11386 return Extract(s, offset, length)
11387
11388

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

9209def substitute(t, *m):
9210 """Apply substitution m on t, m is a list of pairs of the form (from, to).
9211 Every occurrence in t of from is replaced with to.
9212
9213 >>> x = Int('x')
9214 >>> y = Int('y')
9215 >>> substitute(x + 1, (x, y + 1))
9216 y + 1 + 1
9217 >>> f = Function('f', IntSort(), IntSort())
9218 >>> substitute(f(x) + f(y), (f(x), IntVal(1)), (f(y), IntVal(1)))
9219 1 + 1
9220 """
9221 if isinstance(m, tuple):
9222 m1 = _get_args(m)
9223 if isinstance(m1, list) and all(isinstance(p, tuple) for p in m1):
9224 m = m1
9225 if z3_debug():
9226 _z3_assert(is_expr(t), "Z3 expression expected")
9227 _z3_assert(
9228 all([isinstance(p, tuple) and is_expr(p[0]) and is_expr(p[1]) for p in m]),
9229 "Z3 invalid substitution, expression pairs expected.")
9230 _z3_assert(
9231 all([p[0].sort().eq(p[1].sort()) for p in m]),
9232 'Z3 invalid substitution, mismatching "from" and "to" sorts.')
9233 num = len(m)
9234 _from = (Ast * num)()
9235 _to = (Ast * num)()
9236 for i in range(num):
9237 _from[i] = m[i][0].as_ast()
9238 _to[i] = m[i][1].as_ast()
9239 return _to_expr_ref(Z3_substitute(t.ctx.ref(), t.as_ast(), num, _from, _to), t.ctx)
9240
9241
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 9262 of file z3py.py.

9262def substitute_funs(t, *m):
9263 """Apply substitution m on t, m is a list of pairs of a function and expression (from, to)
9264 Every occurrence in to of the function from is replaced with the expression to.
9265 The expression to can have free variables, that refer to the arguments of from.
9266 For examples, see
9267 """
9268 if isinstance(m, tuple):
9269 m1 = _get_args(m)
9270 if isinstance(m1, list) and all(isinstance(p, tuple) for p in m1):
9271 m = m1
9272 if z3_debug():
9273 _z3_assert(is_expr(t), "Z3 expression expected")
9274 _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.")
9275 num = len(m)
9276 _from = (FuncDecl * num)()
9277 _to = (Ast * num)()
9278 for i in range(num):
9279 _from[i] = m[i][0].as_func_decl()
9280 _to[i] = m[i][1].as_ast()
9281 return _to_expr_ref(Z3_substitute_funs(t.ctx.ref(), t.as_ast(), num, _from, _to), t.ctx)
9282
9283
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 9242 of file z3py.py.

9242def substitute_vars(t, *m):
9243 """Substitute the free variables in t with the expression in m.
9244
9245 >>> v0 = Var(0, IntSort())
9246 >>> v1 = Var(1, IntSort())
9247 >>> x = Int('x')
9248 >>> f = Function('f', IntSort(), IntSort(), IntSort())
9249 >>> # replace v0 with x+1 and v1 with x
9250 >>> substitute_vars(f(v0, v1), x + 1, x)
9251 f(x + 1, x)
9252 """
9253 if z3_debug():
9254 _z3_assert(is_expr(t), "Z3 expression expected")
9255 _z3_assert(all([is_expr(n) for n in m]), "Z3 invalid substitution, list of expressions expected.")
9256 num = len(m)
9257 _to = (Ast * num)()
9258 for i in range(num):
9259 _to[i] = m[i].as_ast()
9260 return _to_expr_ref(Z3_substitute_vars(t.ctx.ref(), t.as_ast(), num, _to), t.ctx)
9261
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 11361 of file z3py.py.

11361def SubString(s, offset, length):
11362 """Extract substring or subsequence starting at offset.
11363
11364 This is a convenience function that redirects to Extract(s, offset, length).
11365
11366 >>> s = StringVal("hello world")
11367 >>> SubString(s, 6, 5) # Extract "world"
11368 str.substr("hello world", 6, 5)
11369 >>> simplify(SubString(StringVal("hello"), 1, 3))
11370 "ell"
11371 """
11372 return Extract(s, offset, length)
11373
11374

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

11444def SuffixOf(a, b):
11445 """Check if 'a' is a suffix of 'b'
11446 >>> s1 = SuffixOf("ab", "abc")
11447 >>> simplify(s1)
11448 False
11449 >>> s2 = SuffixOf("bc", "abc")
11450 >>> simplify(s2)
11451 True
11452 """
11453 ctx = _get_ctx2(a, b)
11454 a = _coerce_seq(a, ctx)
11455 b = _coerce_seq(b, ctx)
11456 return BoolRef(Z3_mk_seq_suffix(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
11457
11458
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 9284 of file z3py.py.

9284def Sum(*args):
9285 """Create the sum of the Z3 expressions.
9286
9287 >>> a, b, c = Ints('a b c')
9288 >>> Sum(a, b, c)
9289 a + b + c
9290 >>> Sum([a, b, c])
9291 a + b + c
9292 >>> A = IntVector('a', 5)
9293 >>> Sum(A)
9294 a__0 + a__1 + a__2 + a__3 + a__4
9295 """
9296 args = _get_args(args)
9297 if len(args) == 0:
9298 return 0
9299 ctx = _ctx_from_ast_arg_list(args)
9300 if ctx is None:
9301 return _reduce(lambda a, b: a + b, args, 0)
9302 args = _coerce_expr_list(args, ctx)
9303 if is_bv(args[0]):
9304 return _reduce(lambda a, b: a + b, args, 0)
9305 else:
9306 _args, sz = _to_ast_array(args)
9307 return ArithRef(Z3_mk_add(ctx.ref(), sz, _args), ctx)
9308
9309
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 8863 of file z3py.py.

8863def tactic_description(name, ctx=None):
8864 """Return a short description for the tactic named `name`.
8865
8866 >>> d = tactic_description('simplify')
8867 """
8868 ctx = _get_ctx(ctx)
8869 return Z3_tactic_get_descr(ctx.ref(), name)
8870
8871
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 8852 of file z3py.py.

8852def tactics(ctx=None):
8853 """Return a list of all available tactics in Z3.
8854
8855 >>> l = tactics()
8856 >>> l.count('simplify') == 1
8857 True
8858 """
8859 ctx = _get_ctx(ctx)
8860 return [Z3_get_tactic_name(ctx.ref(), i) for i in range(Z3_get_num_tactics(ctx.ref()))]
8861
8862
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 8720 of file z3py.py.

8720def Then(*ts, **ks):
8721 """Return a tactic that applies the tactics in `*ts` in sequence. Shorthand for AndThen(*ts, **ks).
8722
8723 >>> x, y = Ints('x y')
8724 >>> t = Then(Tactic('simplify'), Tactic('solve-eqs'))
8725 >>> t(And(x == 0, y > x + 1))
8726 [[Not(y <= 1)]]
8727 >>> t(And(x == 0, y > x + 1)).as_expr()
8728 Not(y <= 1)
8729 """
8730 return AndThen(*ts, **ks)
8731
8732

◆ to_Ast()

to_Ast (   ptr)

Definition at line 11803 of file z3py.py.

11803def to_Ast(ptr,):
11804 ast = Ast(ptr)
11805 super(ctypes.c_void_p, ast).__init__(ptr)
11806 return ast
11807

◆ to_AstVectorObj()

to_AstVectorObj (   ptr)

Definition at line 11813 of file z3py.py.

11813def to_AstVectorObj(ptr,):
11814 v = AstVectorObj(ptr)
11815 super(ctypes.c_void_p, v).__init__(ptr)
11816 return v
11817
11818# NB. my-hacky-class only works for a single instance of OnClause
11819# it should be replaced with a proper correlation between OnClause
11820# and object references that can be passed over the FFI.
11821# for UserPropagator we use a global dictionary, which isn't great code.
11822

◆ to_ContextObj()

to_ContextObj (   ptr)

Definition at line 11808 of file z3py.py.

11808def to_ContextObj(ptr,):
11809 ctx = ContextObj(ptr)
11810 super(ctypes.c_void_p, ctx).__init__(ptr)
11811 return ctx
11812

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

3538def ToInt(a):
3539 """ Return the Z3 expression ToInt(a).
3540
3541 >>> x = Real('x')
3542 >>> x.sort()
3543 Real
3544 >>> n = ToInt(x)
3545 >>> n
3546 ToInt(x)
3547 >>> n.sort()
3548 Int
3549 """
3550 if z3_debug():
3551 _z3_assert(a.is_real(), "Z3 real expression expected.")
3552 ctx = a.ctx
3553 return ArithRef(Z3_mk_real2int(ctx.ref(), a.as_ast()), ctx)
3554
3555
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 3518 of file z3py.py.

3518def ToReal(a):
3519 """ Return the Z3 expression ToReal(a).
3520
3521 >>> x = Int('x')
3522 >>> x.sort()
3523 Int
3524 >>> n = ToReal(x)
3525 >>> n
3526 ToReal(x)
3527 >>> n.sort()
3528 Real
3529 """
3530 ctx = a.ctx
3531 if isinstance(a, BoolRef):
3532 return If(a, RealVal(1, ctx), RealVal(0, ctx))
3533 if z3_debug():
3534 _z3_assert(a.is_int(), "Z3 integer expression expected.")
3535 return ArithRef(Z3_mk_int2real(ctx.ref(), a.as_ast()), ctx)
3536
3537
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 11796 of file z3py.py.

11796def TransitiveClosure(f):
11797 """Given a binary relation R, such that the two arguments have the same sort
11798 create the transitive closure relation R+.
11799 The transitive closure R+ is a new relation.
11800 """
11801 return FuncDeclRef(Z3_mk_transitive_closure(f.ctx_ref(), f.ast), f.ctx)
11802
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 11788 of file z3py.py.

11788def TreeOrder(a, index):
11789 return FuncDeclRef(Z3_mk_tree_order(a.ctx_ref(), a.ast, index), a.ctx)
11790
11791
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 8843 of file z3py.py.

8843def TryFor(t, ms, ctx=None):
8844 """Return a tactic that applies `t` to a given goal for `ms` milliseconds.
8845
8846 If `t` does not terminate in `ms` milliseconds, then it fails.
8847 """
8848 t = _to_tactic(t, ctx)
8849 return Tactic(Z3_tactic_try_for(t.ctx.ref(), t.tactic, ms), t.ctx)
8850
8851
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 5592 of file z3py.py.

5592def TupleSort(name, sorts, ctx=None):
5593 """Create a named tuple sort base on a set of underlying sorts
5594 Example:
5595 >>> pair, mk_pair, (first, second) = TupleSort("pair", [IntSort(), StringSort()])
5596 """
5597 tuple = Datatype(name, ctx)
5598 projects = [("project%d" % i, sorts[i]) for i in range(len(sorts))]
5599 tuple.declare(name, *projects)
5600 tuple = tuple.create()
5601 return tuple, tuple.constructor(0), [tuple.accessor(0, i) for i in range(len(sorts))]
5602
5603

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

4426def UDiv(a, b):
4427 """Create the Z3 expression (unsigned) division `self / other`.
4428
4429 Use the operator / for signed division.
4430
4431 >>> x = BitVec('x', 32)
4432 >>> y = BitVec('y', 32)
4433 >>> UDiv(x, y)
4434 UDiv(x, y)
4435 >>> UDiv(x, y).sort()
4436 BitVec(32)
4437 >>> (x / y).sexpr()
4438 '(bvsdiv x y)'
4439 >>> UDiv(x, y).sexpr()
4440 '(bvudiv x y)'
4441 """
4442 _check_bv_args(a, b)
4443 a, b = _coerce_exprs(a, b)
4444 return BitVecRef(Z3_mk_bvudiv(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4445
4446
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 4390 of file z3py.py.

4390def UGE(a, b):
4391 """Create the Z3 expression (unsigned) `other >= self`.
4392
4393 Use the operator >= for signed greater than or equal to.
4394
4395 >>> x, y = BitVecs('x y', 32)
4396 >>> UGE(x, y)
4397 UGE(x, y)
4398 >>> (x >= y).sexpr()
4399 '(bvsge x y)'
4400 >>> UGE(x, y).sexpr()
4401 '(bvuge x y)'
4402 """
4403 _check_bv_args(a, b)
4404 a, b = _coerce_exprs(a, b)
4405 return BoolRef(Z3_mk_bvuge(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4406
4407
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 4408 of file z3py.py.

4408def UGT(a, b):
4409 """Create the Z3 expression (unsigned) `other > self`.
4410
4411 Use the operator > for signed greater than.
4412
4413 >>> x, y = BitVecs('x y', 32)
4414 >>> UGT(x, y)
4415 UGT(x, y)
4416 >>> (x > y).sexpr()
4417 '(bvsgt x y)'
4418 >>> UGT(x, y).sexpr()
4419 '(bvugt x y)'
4420 """
4421 _check_bv_args(a, b)
4422 a, b = _coerce_exprs(a, b)
4423 return BoolRef(Z3_mk_bvugt(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4424
4425
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 4354 of file z3py.py.

4354def ULE(a, b):
4355 """Create the Z3 expression (unsigned) `other <= self`.
4356
4357 Use the operator <= for signed less than or equal to.
4358
4359 >>> x, y = BitVecs('x y', 32)
4360 >>> ULE(x, y)
4361 ULE(x, y)
4362 >>> (x <= y).sexpr()
4363 '(bvsle x y)'
4364 >>> ULE(x, y).sexpr()
4365 '(bvule x y)'
4366 """
4367 _check_bv_args(a, b)
4368 a, b = _coerce_exprs(a, b)
4369 return BoolRef(Z3_mk_bvule(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4370
4371
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 4372 of file z3py.py.

4372def ULT(a, b):
4373 """Create the Z3 expression (unsigned) `other < self`.
4374
4375 Use the operator < for signed less than.
4376
4377 >>> x, y = BitVecs('x y', 32)
4378 >>> ULT(x, y)
4379 ULT(x, y)
4380 >>> (x < y).sexpr()
4381 '(bvslt x y)'
4382 >>> ULT(x, y).sexpr()
4383 '(bvult x y)'
4384 """
4385 _check_bv_args(a, b)
4386 a, b = _coerce_exprs(a, b)
4387 return BoolRef(Z3_mk_bvult(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4388
4389
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 11646 of file z3py.py.

11646def Union(*args):
11647 """Create union of regular expressions.
11648 >>> re = Union(Re("a"), Re("b"), Re("c"))
11649 >>> print (simplify(InRe("d", re)))
11650 False
11651 """
11652 args = _get_args(args)
11653 sz = len(args)
11654 if z3_debug():
11655 _z3_assert(sz > 0, "At least one argument expected.")
11656 _z3_assert(all([is_re(a) for a in args]), "All arguments must be regular expressions.")
11657 if sz == 1:
11658 return args[0]
11659 ctx = args[0].ctx
11660 v = (Ast * sz)()
11661 for i in range(sz):
11662 v[i] = args[i].as_ast()
11663 return ReRef(Z3_mk_re_union(ctx.ref(), sz, v), ctx)
11664
11665
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 11424 of file z3py.py.

11424def Unit(a):
11425 """Create a singleton sequence"""
11426 return SeqRef(Z3_mk_seq_unit(a.ctx_ref(), a.as_ast()), a.ctx)
11427
11428
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 4937 of file z3py.py.

4937def Update(a, *args):
4938 """Return a Z3 store array expression.
4939
4940 >>> a = Array('a', IntSort(), IntSort())
4941 >>> i, v = Ints('i v')
4942 >>> s = Update(a, i, v)
4943 >>> s.sort()
4944 Array(Int, Int)
4945 >>> prove(s[i] == v)
4946 proved
4947 >>> j = Int('j')
4948 >>> prove(Implies(i != j, s[j] == a[j]))
4949 proved
4950 """
4951 if z3_debug():
4952 _z3_assert(is_array_sort(a), "First argument must be a Z3 array expression")
4953 args = _get_args(args)
4954 ctx = a.ctx
4955 if len(args) <= 1:
4956 raise Z3Exception("array update requires index and value arguments")
4957 if len(args) == 2:
4958 i = args[0]
4959 v = args[1]
4960 i = a.sort().domain().cast(i)
4961 v = a.sort().range().cast(v)
4962 return _to_expr_ref(Z3_mk_store(ctx.ref(), a.as_ast(), i.as_ast(), v.as_ast()), ctx)
4963 v = a.sort().range().cast(args[-1])
4964 idxs = [a.sort().domain_n(i).cast(args[i]) for i in range(len(args)-1)]
4965 _args, sz = _to_ast_array(idxs)
4966 return _to_expr_ref(Z3_mk_store_n(ctx.ref(), a.as_ast(), sz, _args, v.as_ast()), ctx)
4967
4968
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 4447 of file z3py.py.

4447def URem(a, b):
4448 """Create the Z3 expression (unsigned) remainder `self % other`.
4449
4450 Use the operator % for signed modulus, and SRem() for signed remainder.
4451
4452 >>> x = BitVec('x', 32)
4453 >>> y = BitVec('y', 32)
4454 >>> URem(x, y)
4455 URem(x, y)
4456 >>> URem(x, y).sort()
4457 BitVec(32)
4458 >>> (x % y).sexpr()
4459 '(bvsmod x y)'
4460 >>> URem(x, y).sexpr()
4461 '(bvurem x y)'
4462 """
4463 _check_bv_args(a, b)
4464 a, b = _coerce_exprs(a, b)
4465 return BitVecRef(Z3_mk_bvurem(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4466
4467
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 11966 of file z3py.py.

11966def user_prop_binding(ctx, cb, q_ref, inst_ref):
11967 prop = _prop_closures.get(ctx)
11968 old_cb = prop.cb
11969 prop.cb = cb
11970 q = _to_expr_ref(to_Ast(q_ref), prop.ctx())
11971 inst = _to_expr_ref(to_Ast(inst_ref), prop.ctx())
11972 r = prop.binding(q, inst)
11973 prop.cb = old_cb
11974 return r
11975
11976

◆ user_prop_created()

user_prop_created (   ctx,
  cb,
  id 
)

Definition at line 11924 of file z3py.py.

11924def user_prop_created(ctx, cb, id):
11925 prop = _prop_closures.get(ctx)
11926 old_cb = prop.cb
11927 prop.cb = cb
11928 id = _to_expr_ref(to_Ast(id), prop.ctx())
11929 prop.created(id)
11930 prop.cb = old_cb
11931
11932

◆ user_prop_decide()

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

Definition at line 11958 of file z3py.py.

11958def user_prop_decide(ctx, cb, t_ref, idx, phase):
11959 prop = _prop_closures.get(ctx)
11960 old_cb = prop.cb
11961 prop.cb = cb
11962 t = _to_expr_ref(to_Ast(t_ref), prop.ctx())
11963 prop.decide(t, idx, phase)
11964 prop.cb = old_cb
11965

◆ user_prop_diseq()

user_prop_diseq (   ctx,
  cb,
  x,
  y 
)

Definition at line 11949 of file z3py.py.

11949def user_prop_diseq(ctx, cb, x, y):
11950 prop = _prop_closures.get(ctx)
11951 old_cb = prop.cb
11952 prop.cb = cb
11953 x = _to_expr_ref(to_Ast(x), prop.ctx())
11954 y = _to_expr_ref(to_Ast(y), prop.ctx())
11955 prop.diseq(x, y)
11956 prop.cb = old_cb
11957

◆ user_prop_eq()

user_prop_eq (   ctx,
  cb,
  x,
  y 
)

Definition at line 11940 of file z3py.py.

11940def user_prop_eq(ctx, cb, x, y):
11941 prop = _prop_closures.get(ctx)
11942 old_cb = prop.cb
11943 prop.cb = cb
11944 x = _to_expr_ref(to_Ast(x), prop.ctx())
11945 y = _to_expr_ref(to_Ast(y), prop.ctx())
11946 prop.eq(x, y)
11947 prop.cb = old_cb
11948

◆ user_prop_final()

user_prop_final (   ctx,
  cb 
)

Definition at line 11933 of file z3py.py.

11933def user_prop_final(ctx, cb):
11934 prop = _prop_closures.get(ctx)
11935 old_cb = prop.cb
11936 prop.cb = cb
11937 prop.final()
11938 prop.cb = old_cb
11939

◆ user_prop_fixed()

user_prop_fixed (   ctx,
  cb,
  id,
  value 
)

Definition at line 11915 of file z3py.py.

11915def user_prop_fixed(ctx, cb, id, value):
11916 prop = _prop_closures.get(ctx)
11917 old_cb = prop.cb
11918 prop.cb = cb
11919 id = _to_expr_ref(to_Ast(id), prop.ctx())
11920 value = _to_expr_ref(to_Ast(value), prop.ctx())
11921 prop.fixed(id, value)
11922 prop.cb = old_cb
11923

◆ user_prop_fresh()

user_prop_fresh (   ctx,
  _new_ctx 
)

Definition at line 11901 of file z3py.py.

11901def user_prop_fresh(ctx, _new_ctx):
11902 _prop_closures.set_threaded()
11903 prop = _prop_closures.get(ctx)
11904 nctx = Context()
11905 Z3_del_context(nctx.ctx)
11906 new_ctx = to_ContextObj(_new_ctx)
11907 nctx.ctx = new_ctx
11908 nctx.eh = Z3_set_error_handler(new_ctx, z3_error_handler)
11909 nctx.owner = False
11910 new_prop = prop.fresh(nctx)
11911 _prop_closures.set(new_prop.id, new_prop)
11912 return new_prop.id
11913
11914
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 11895 of file z3py.py.

11895def user_prop_pop(ctx, cb, num_scopes):
11896 prop = _prop_closures.get(ctx)
11897 prop.cb = cb
11898 prop.pop(num_scopes)
11899
11900

◆ user_prop_push()

user_prop_push (   ctx,
  cb 
)

Definition at line 11889 of file z3py.py.

11889def user_prop_push(ctx, cb):
11890 prop = _prop_closures.get(ctx)
11891 prop.cb = cb
11892 prop.push()
11893
11894

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

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

9137def When(p, t, ctx=None):
9138 """Return a tactic that applies tactic `t` only if probe `p` evaluates to true.
9139 Otherwise, it returns the input goal unmodified.
9140
9141 >>> t = When(Probe('size') > 2, Tactic('simplify'))
9142 >>> x, y = Ints('x y')
9143 >>> g = Goal()
9144 >>> g.add(x > 0)
9145 >>> g.add(y > 0)
9146 >>> t(g)
9147 [[x > 0, y > 0]]
9148 >>> g.add(x == y + 1)
9149 >>> t(g)
9150 [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
9151 """
9152 p = _to_probe(p, ctx)
9153 t = _to_tactic(t, ctx)
9154 return Tactic(Z3_tactic_when(t.ctx.ref(), p.probe, t.tactic), t.ctx)
9155
9156
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 8794 of file z3py.py.

8794def With(t, *args, **keys):
8795 """Return a tactic that applies tactic `t` using the given configuration options.
8796
8797 >>> x, y = Ints('x y')
8798 >>> t = With(Tactic('simplify'), som=True)
8799 >>> t((x + 1)*(y + 2) == 0)
8800 [[2*x + y + x*y == -2]]
8801 """
8802 ctx = keys.pop("ctx", None)
8803 t = _to_tactic(t, ctx)
8804 p = args2params(args, keys, t.ctx)
8805 return Tactic(Z3_tactic_using_params(t.ctx.ref(), t.tactic, p.params), t.ctx)
8806
8807
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 8808 of file z3py.py.

8808def WithParams(t, p):
8809 """Return a tactic that applies tactic `t` using the given configuration options.
8810
8811 >>> x, y = Ints('x y')
8812 >>> p = ParamsRef()
8813 >>> p.set("som", True)
8814 >>> t = WithParams(Tactic('simplify'), p)
8815 >>> t((x + 1)*(y + 2) == 0)
8816 [[2*x + y + x*y == -2]]
8817 """
8818 t = _to_tactic(t, None)
8819 return Tactic(Z3_tactic_using_params(t.ctx.ref(), t.tactic, p.params), t.ctx)
8820
8821

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

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

4583def ZeroExt(n, a):
4584 """Return a bit-vector expression with `n` extra zero-bits.
4585
4586 >>> x = BitVec('x', 16)
4587 >>> n = ZeroExt(8, x)
4588 >>> n.size()
4589 24
4590 >>> n
4591 ZeroExt(8, x)
4592 >>> n.sort()
4593 BitVec(24)
4594 >>> v0 = BitVecVal(2, 2)
4595 >>> v0
4596 2
4597 >>> v0.size()
4598 2
4599 >>> v = simplify(ZeroExt(6, v0))
4600 >>> v
4601 2
4602 >>> v.size()
4603 8
4604 """
4605 if z3_debug():
4606 _z3_assert(_is_int(n), "First argument must be an integer")
4607 _z3_assert(is_bv(a), "Second argument must be a Z3 bit-vector expression")
4608 return BitVecRef(Z3_mk_zero_ext(a.ctx_ref(), n, a.as_ast()), a.ctx)
4609
4610
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 9689 of file z3py.py.

◆ _dflt_fpsort_sbits

int _dflt_fpsort_sbits = 53
protected

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

◆ _main_ctx

_main_ctx = None
protected

Definition at line 263 of file z3py.py.

◆ _my_hacky_class

_my_hacky_class = None
protected

Definition at line 11823 of file z3py.py.

◆ _on_clause_eh

_on_clause_eh = Z3_on_clause_eh(on_clause_eh)
protected

Definition at line 11831 of file z3py.py.

◆ _on_model_eh

_on_model_eh = on_model_eh_type(_global_on_model)
protected

Definition at line 8191 of file z3py.py.

◆ _on_models

dict _on_models = {}
protected

Definition at line 8183 of file z3py.py.

◆ _prop_closures

_prop_closures = None
protected

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

◆ _user_prop_binding

_user_prop_binding = Z3_on_binding_eh(user_prop_binding)
protected

Definition at line 11986 of file z3py.py.

◆ _user_prop_created

_user_prop_created = Z3_created_eh(user_prop_created)
protected

Definition at line 11981 of file z3py.py.

◆ _user_prop_decide

_user_prop_decide = Z3_decide_eh(user_prop_decide)
protected

Definition at line 11985 of file z3py.py.

◆ _user_prop_diseq

_user_prop_diseq = Z3_eq_eh(user_prop_diseq)
protected

Definition at line 11984 of file z3py.py.

◆ _user_prop_eq

_user_prop_eq = Z3_eq_eh(user_prop_eq)
protected

Definition at line 11983 of file z3py.py.

◆ _user_prop_final

_user_prop_final = Z3_final_eh(user_prop_final)
protected

Definition at line 11982 of file z3py.py.

◆ _user_prop_fixed

_user_prop_fixed = Z3_fixed_eh(user_prop_fixed)
protected

Definition at line 11980 of file z3py.py.

◆ _user_prop_fresh

_user_prop_fresh = Z3_fresh_eh(user_prop_fresh)
protected

Definition at line 11979 of file z3py.py.

◆ _user_prop_pop

_user_prop_pop = Z3_pop_eh(user_prop_pop)
protected

Definition at line 11978 of file z3py.py.

◆ _user_prop_push

_user_prop_push = Z3_push_eh(user_prop_push)
protected

Definition at line 11977 of file z3py.py.

◆ sat

Definition at line 7154 of file z3py.py.

◆ unknown

Definition at line 7156 of file z3py.py.

◆ unsat

Definition at line 7155 of file z3py.py.

◆ Z3_DEBUG

Z3_DEBUG = __debug__

Definition at line 67 of file z3py.py.