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

8645def _and_then(t1, t2, ctx=None):
8646 t1 = _to_tactic(t1, ctx)
8647 t2 = _to_tactic(t2, ctx)
8648 if z3_debug():
8649 _z3_assert(t1.ctx == t2.ctx, "Context mismatch")
8650 return Tactic(Z3_tactic_and_then(t1.ctx.ref(), t1.tactic, t2.tactic), t1.ctx)
8651
8652
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 4775 of file z3py.py.

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

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

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

10757def _check_fp_args(a, b):
10758 if z3_debug():
10759 _z3_assert(is_fp(a) or is_fp(b), "First or second argument must be a Z3 floating-point expression")
10760
10761

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

11200def _coerce_char(ch, ctx=None):
11201 if isinstance(ch, str):
11202 ctx = _get_ctx(ctx)
11203 ch = CharVal(ch, ctx)
11204 if not is_expr(ch):
11205 raise Z3Exception("Character expression expected")
11206 return ch
11207

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

9706def _coerce_fp_expr_list(alist, ctx):
9707 first_fp_sort = None
9708 for a in alist:
9709 if is_fp(a):
9710 if first_fp_sort is None:
9711 first_fp_sort = a.sort()
9712 elif first_fp_sort == a.sort():
9713 pass # OK, same as before
9714 else:
9715 # we saw at least 2 different float sorts; something will
9716 # throw a sort mismatch later, for now assume None.
9717 first_fp_sort = None
9718 break
9719
9720 r = []
9721 for i in range(len(alist)):
9722 a = alist[i]
9723 is_repr = isinstance(a, str) and a.contains("2**(") and a.endswith(")")
9724 if is_repr or _is_int(a) or isinstance(a, (float, bool)):
9725 r.append(FPVal(a, None, first_fp_sort, ctx))
9726 else:
9727 r.append(a)
9728 return _coerce_expr_list(r, ctx)
9729
9730
9731# FP Sorts
9732

◆ _coerce_seq()

_coerce_seq (   s,
  ctx = None 
)
protected

Definition at line 11250 of file z3py.py.

11250def _coerce_seq(s, ctx=None):
11251 if isinstance(s, str):
11252 ctx = _get_ctx(ctx)
11253 s = StringVal(s, ctx)
11254 if not is_expr(s):
11255 raise Z3Exception("Non-expression passed as a sequence")
11256 if not is_seq(s):
11257 raise Z3Exception("Non-sequence passed as a sequence")
11258 return s
11259
11260

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

9702def _dflt_fps(ctx=None):
9703 return get_default_fp_sort(ctx)
9704
9705

◆ _dflt_rm()

_dflt_rm (   ctx = None)
protected

Definition at line 9698 of file z3py.py.

9698def _dflt_rm(ctx=None):
9699 return get_default_rounding_mode(ctx)
9700
9701

◆ _dict2darray()

_dict2darray (   decls,
  ctx 
)
protected

Definition at line 9571 of file z3py.py.

9571def _dict2darray(decls, ctx):
9572 sz = len(decls)
9573 _names = (Symbol * sz)()
9574 _decls = (FuncDecl * sz)()
9575 i = 0
9576 for k in decls:
9577 v = decls[k]
9578 if z3_debug():
9579 _z3_assert(isinstance(k, str), "String expected")
9580 _z3_assert(is_func_decl(v) or is_const(v), "Z3 declaration or constant expected")
9581 _names[i] = to_symbol(k, ctx)
9582 if is_const(v):
9583 _decls[i] = v.decl().ast
9584 else:
9585 _decls[i] = v.ast
9586 i = i + 1
9587 return sz, _names, _decls
9588

◆ _dict2sarray()

_dict2sarray (   sorts,
  ctx 
)
protected

Definition at line 9555 of file z3py.py.

9555def _dict2sarray(sorts, ctx):
9556 sz = len(sorts)
9557 _names = (Symbol * sz)()
9558 _sorts = (Sort * sz)()
9559 i = 0
9560 for k in sorts:
9561 v = sorts[k]
9562 if z3_debug():
9563 _z3_assert(isinstance(k, str), "String expected")
9564 _z3_assert(is_sort(v), "Z3 sort expected")
9565 _names[i] = to_symbol(k, ctx)
9566 _sorts[i] = v.ast
9567 i = i + 1
9568 return sz, _names, _sorts
9569
9570

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

11261def _get_ctx2(a, b, ctx=None):
11262 if is_expr(a):
11263 return a.ctx
11264 if is_expr(b):
11265 return b.ctx
11266 if ctx is None:
11267 ctx = main_ctx()
11268 return ctx
11269
11270

◆ _global_on_model()

_global_on_model (   ctx)
protected

Definition at line 8147 of file z3py.py.

8147def _global_on_model(ctx):
8148 (fn, mdl) = _on_models[ctx]
8149 fn(mdl)
8150
8151

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

2871def _is_algebraic(ctx, a):
2872 return Z3_is_algebraic_number(ctx.ref(), a)
2873
2874
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 2867 of file z3py.py.

2867def _is_numeral(ctx, a):
2868 return Z3_is_numeral_ast(ctx.ref(), a)
2869
2870
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 10545 of file z3py.py.

10545def _mk_fp_bin(f, rm, a, b, ctx):
10546 ctx = _get_ctx(ctx)
10547 [a, b] = _coerce_fp_expr_list([a, b], ctx)
10548 if z3_debug():
10549 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
10550 _z3_assert(is_fp(a) or is_fp(b), "Second or third argument must be a Z3 floating-point expression")
10551 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast()), ctx)
10552
10553

◆ _mk_fp_bin_norm()

_mk_fp_bin_norm (   f,
  a,
  b,
  ctx 
)
protected

Definition at line 10554 of file z3py.py.

10554def _mk_fp_bin_norm(f, a, b, ctx):
10555 ctx = _get_ctx(ctx)
10556 [a, b] = _coerce_fp_expr_list([a, b], ctx)
10557 if z3_debug():
10558 _z3_assert(is_fp(a) or is_fp(b), "First or second argument must be a Z3 floating-point expression")
10559 return FPRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
10560
10561

◆ _mk_fp_bin_pred()

_mk_fp_bin_pred (   f,
  a,
  b,
  ctx 
)
protected

Definition at line 10562 of file z3py.py.

10562def _mk_fp_bin_pred(f, a, b, ctx):
10563 ctx = _get_ctx(ctx)
10564 [a, b] = _coerce_fp_expr_list([a, b], ctx)
10565 if z3_debug():
10566 _z3_assert(is_fp(a) or is_fp(b), "First or second argument must be a Z3 floating-point expression")
10567 return BoolRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
10568
10569

◆ _mk_fp_tern()

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

Definition at line 10570 of file z3py.py.

10570def _mk_fp_tern(f, rm, a, b, c, ctx):
10571 ctx = _get_ctx(ctx)
10572 [a, b, c] = _coerce_fp_expr_list([a, b, c], ctx)
10573 if z3_debug():
10574 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
10575 _z3_assert(is_fp(a) or is_fp(b) or is_fp(
10576 c), "Second, third or fourth argument must be a Z3 floating-point expression")
10577 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
10578
10579

◆ _mk_fp_unary()

_mk_fp_unary (   f,
  rm,
  a,
  ctx 
)
protected

Definition at line 10528 of file z3py.py.

10528def _mk_fp_unary(f, rm, a, ctx):
10529 ctx = _get_ctx(ctx)
10530 [a] = _coerce_fp_expr_list([a], ctx)
10531 if z3_debug():
10532 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
10533 _z3_assert(is_fp(a), "Second argument must be a Z3 floating-point expression")
10534 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast()), ctx)
10535
10536

◆ _mk_fp_unary_pred()

_mk_fp_unary_pred (   f,
  a,
  ctx 
)
protected

Definition at line 10537 of file z3py.py.

10537def _mk_fp_unary_pred(f, a, ctx):
10538 ctx = _get_ctx(ctx)
10539 [a] = _coerce_fp_expr_list([a], ctx)
10540 if z3_debug():
10541 _z3_assert(is_fp(a), "First argument must be a Z3 floating-point expression")
10542 return BoolRef(f(ctx.ref(), a.as_ast()), ctx)
10543
10544

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

8653def _or_else(t1, t2, ctx=None):
8654 t1 = _to_tactic(t1, ctx)
8655 t2 = _to_tactic(t2, ctx)
8656 if z3_debug():
8657 _z3_assert(t1.ctx == t2.ctx, "Context mismatch")
8658 return Tactic(Z3_tactic_or_else(t1.ctx.ref(), t1.tactic, t2.tactic), t1.ctx)
8659
8660
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 9344 of file z3py.py.

9344def _pb_args_coeffs(args, default_ctx=None):
9345 args = _get_args_ast_list(args)
9346 if len(args) == 0:
9347 return _get_ctx(default_ctx), 0, (Ast * 0)(), (ctypes.c_int * 0)()
9348 args = [_reorder_pb_arg(arg) for arg in args]
9349 args, coeffs = zip(*args)
9350 if z3_debug():
9351 _z3_assert(len(args) > 0, "Non empty list of arguments expected")
9352 ctx = _ctx_from_ast_arg_list(args)
9353 if z3_debug():
9354 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
9355 args = _coerce_expr_list(args, ctx)
9356 _args, sz = _to_ast_array(args)
9357 _coeffs = (ctypes.c_int * len(coeffs))()
9358 for i in range(len(coeffs)):
9359 _z3_check_cint_overflow(coeffs[i], "coefficient")
9360 _coeffs[i] = coeffs[i]
9361 return ctx, sz, _args, _coeffs, args
9362
9363

◆ _probe_and()

_probe_and (   args,
  ctx 
)
protected

Definition at line 9068 of file z3py.py.

9068def _probe_and(args, ctx):
9069 return _probe_nary(Z3_probe_and, args, ctx)
9070
9071

Referenced by And().

◆ _probe_nary()

_probe_nary (   f,
  args,
  ctx 
)
protected

Definition at line 9058 of file z3py.py.

9058def _probe_nary(f, args, ctx):
9059 if z3_debug():
9060 _z3_assert(len(args) > 0, "At least one argument expected")
9061 num = len(args)
9062 r = _to_probe(args[0], ctx)
9063 for i in range(num - 1):
9064 r = Probe(f(ctx.ref(), r.probe, _to_probe(args[i + 1], ctx).probe), ctx)
9065 return r
9066
9067

◆ _probe_or()

_probe_or (   args,
  ctx 
)
protected

Definition at line 9072 of file z3py.py.

9072def _probe_or(args, ctx):
9073 return _probe_nary(Z3_probe_or, args, ctx)
9074
9075

Referenced by Or().

◆ _prove_html()

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

Definition at line 9535 of file z3py.py.

9535def _prove_html(claim, show=False, **keywords):
9536 """Version of function `prove` that renders HTML."""
9537 if z3_debug():
9538 _z3_assert(is_bool(claim), "Z3 Boolean expression expected")
9539 s = Solver()
9540 s.set(**keywords)
9541 s.add(Not(claim))
9542 if show:
9543 print(s)
9544 r = s.check()
9545 if r == unsat:
9546 print("<b>proved</b>")
9547 elif r == unknown:
9548 print("<b>failed to prove</b>")
9549 print(s.model())
9550 else:
9551 print("<b>counterexample</b>")
9552 print(s.model())
9553
9554

◆ _py2expr()

_py2expr (   a,
  ctx = None 
)
protected

Definition at line 3272 of file z3py.py.

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

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

9337def _reorder_pb_arg(arg):
9338 a, b = arg
9339 if not _is_int(b) and _is_int(a):
9340 return b, a
9341 return arg
9342
9343

◆ _solve_html()

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

Definition at line 9486 of file z3py.py.

9486def _solve_html(*args, **keywords):
9487 """Version of function `solve` that renders HTML output."""
9488 show = keywords.pop("show", False)
9489 s = Solver()
9490 s.set(**keywords)
9491 s.add(*args)
9492 if show:
9493 print("<b>Problem:</b>")
9494 print(s)
9495 r = s.check()
9496 if r == unsat:
9497 print("<b>no solution</b>")
9498 elif r == unknown:
9499 print("<b>failed to solve</b>")
9500 try:
9501 print(s.model())
9502 except Z3Exception:
9503 return
9504 else:
9505 if show:
9506 print("<b>Solution:</b>")
9507 print(s.model())
9508
9509

◆ _solve_using_html()

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

Definition at line 9510 of file z3py.py.

9510def _solve_using_html(s, *args, **keywords):
9511 """Version of function `solve_using` that renders HTML."""
9512 show = keywords.pop("show", False)
9513 if z3_debug():
9514 _z3_assert(isinstance(s, Solver), "Solver object expected")
9515 s.set(**keywords)
9516 s.add(*args)
9517 if show:
9518 print("<b>Problem:</b>")
9519 print(s)
9520 r = s.check()
9521 if r == unsat:
9522 print("<b>no solution</b>")
9523 elif r == unknown:
9524 print("<b>failed to solve</b>")
9525 try:
9526 print(s.model())
9527 except Z3Exception:
9528 return
9529 else:
9530 if show:
9531 print("<b>Solution:</b>")
9532 print(s.model())
9533
9534

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

10290def _to_float_str(val, exp=0):
10291 if isinstance(val, float):
10292 if math.isnan(val):
10293 res = "NaN"
10294 elif val == 0.0:
10295 sone = math.copysign(1.0, val)
10296 if sone < 0.0:
10297 return "-0.0"
10298 else:
10299 return "+0.0"
10300 elif val == float("+inf"):
10301 res = "+oo"
10302 elif val == float("-inf"):
10303 res = "-oo"
10304 else:
10305 v = val.as_integer_ratio()
10306 num = v[0]
10307 den = v[1]
10308 rvs = str(num) + "/" + str(den)
10309 res = rvs + "p" + _to_int_str(exp)
10310 elif isinstance(val, bool):
10311 if val:
10312 res = "1.0"
10313 else:
10314 res = "0.0"
10315 elif _is_int(val):
10316 res = str(val)
10317 elif isinstance(val, str):
10318 inx = val.find("*(2**")
10319 if inx == -1:
10320 res = val
10321 elif val[-1] == ")":
10322 res = val[0:inx]
10323 exp = str(int(val[inx + 5:-1]) + int(exp))
10324 else:
10325 _z3_assert(False, "String does not have floating-point numeral form.")
10326 elif z3_debug():
10327 _z3_assert(False, "Python value cannot be used to create floating-point numerals.")
10328 if exp == 0:
10329 return res
10330 else:
10331 return res + "p" + exp
10332
10333

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

8629def _to_goal(a):
8630 if isinstance(a, BoolRef):
8631 goal = Goal(ctx=a.ctx)
8632 goal.add(a)
8633 return goal
8634 else:
8635 return a
8636
8637

◆ _to_int_str()

_to_int_str (   val)
protected

Definition at line 3321 of file z3py.py.

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

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

9012def _to_probe(p, ctx=None):
9013 if is_probe(p):
9014 return p
9015 else:
9016 return Probe(p, ctx)
9017
9018

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

8638def _to_tactic(t, ctx=None):
8639 if isinstance(t, Tactic):
8640 return t
8641 else:
8642 return Tactic(t, ctx)
8643
8644

◆ _valid_accessor()

_valid_accessor (   acc)
protected

Datatypes.

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

Definition at line 5207 of file z3py.py.

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

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

9296def Abs(arg):
9297 """Create the absolute value of an arithmetic expression"""
9298 return If(arg > 0, arg, -arg)
9299
9300

◆ AllChar()

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

Definition at line 11733 of file z3py.py.

11733def AllChar(regex_sort, ctx=None):
11734 """Create a regular expression that accepts all single character strings
11735 """
11736 return ReRef(Z3_mk_re_allchar(regex_sort.ctx_ref(), regex_sort.ast), regex_sort.ctx)
11737
11738# Special Relations
11739
11740
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 8661 of file z3py.py.

8661def AndThen(*ts, **ks):
8662 """Return a tactic that applies the tactics in `*ts` in sequence.
8663
8664 >>> x, y = Ints('x y')
8665 >>> t = AndThen(Tactic('simplify'), Tactic('solve-eqs'))
8666 >>> t(And(x == 0, y > x + 1))
8667 [[Not(y <= 1)]]
8668 >>> t(And(x == 0, y > x + 1)).as_expr()
8669 Not(y <= 1)
8670 """
8671 if z3_debug():
8672 _z3_assert(len(ts) >= 2, "At least two arguments expected")
8673 ctx = ks.get("ctx", None)
8674 num = len(ts)
8675 r = ts[0]
8676 for i in range(num - 1):
8677 r = _and_then(r, ts[i + 1], ctx)
8678 return r
8679
8680

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

5682def args2params(arguments, keywords, ctx=None):
5683 """Convert python arguments into a Z3_params object.
5684 A ':' is added to the keywords, and '_' is replaced with '-'
5685
5686 >>> args2params(['model', True, 'relevancy', 2], {'elim_and' : True})
5687 (params model true relevancy 2 elim_and true)
5688 """
5689 if z3_debug():
5690 _z3_assert(len(arguments) % 2 == 0, "Argument list must have an even number of elements.")
5691 prev = None
5692 r = ParamsRef(ctx)
5693 for a in arguments:
5694 if prev is None:
5695 prev = a
5696 else:
5697 r.set(prev, a)
5698 prev = None
5699 for k in keywords:
5700 v = keywords[k]
5701 r.set(k, v)
5702 return r
5703
5704

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

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

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

9319def AtLeast(*args):
9320 """Create an at-least Pseudo-Boolean k constraint.
9321
9322 >>> a, b, c = Bools('a b c')
9323 >>> f = AtLeast(a, b, c, 2)
9324 """
9325 args = _get_args(args)
9326 if z3_debug():
9327 _z3_assert(len(args) > 1, "Non empty list of arguments expected")
9328 ctx = _ctx_from_ast_arg_list(args)
9329 if z3_debug():
9330 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
9331 args1 = _coerce_expr_list(args[:-1], ctx)
9332 k = args[-1]
9333 _args, sz = _to_ast_array(args1)
9334 return BoolRef(Z3_mk_atleast(ctx.ref(), sz, _args, k), ctx)
9335
9336
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 9301 of file z3py.py.

9301def AtMost(*args):
9302 """Create an at-most Pseudo-Boolean k constraint.
9303
9304 >>> a, b, c = Bools('a b c')
9305 >>> f = AtMost(a, b, c, 2)
9306 """
9307 args = _get_args(args)
9308 if z3_debug():
9309 _z3_assert(len(args) > 1, "Non empty list of arguments expected")
9310 ctx = _ctx_from_ast_arg_list(args)
9311 if z3_debug():
9312 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
9313 args1 = _coerce_expr_list(args[:-1], ctx)
9314 k = args[-1]
9315 _args, sz = _to_ast_array(args1)
9316 return BoolRef(Z3_mk_atmost(ctx.ref(), sz, _args, k), ctx)
9317
9318
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 4191 of file z3py.py.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

◆ CharFromBv()

CharFromBv (   bv)

Definition at line 11233 of file z3py.py.

11233def CharFromBv(bv):
11234 if not is_expr(bv):
11235 raise Z3Exception("Bit-vector expression needed")
11236 return _to_expr_ref(Z3_mk_char_from_bv(bv.ctx_ref(), bv.as_ast()), bv.ctx)
11237
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 11246 of file z3py.py.

11246def CharIsDigit(ch, ctx=None):
11247 ch = _coerce_char(ch, ctx)
11248 return ch.is_digit()
11249

◆ CharSort()

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

Definition at line 11129 of file z3py.py.

11129def CharSort(ctx=None):
11130 """Create a character sort
11131 >>> ch = CharSort()
11132 >>> print(ch)
11133 Char
11134 """
11135 ctx = _get_ctx(ctx)
11136 return CharSortRef(Z3_mk_char_sort(ctx.ref()), ctx)
11137
11138
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 11238 of file z3py.py.

11238def CharToBv(ch, ctx=None):
11239 ch = _coerce_char(ch, ctx)
11240 return ch.to_bv()
11241

◆ CharToInt()

CharToInt (   ch,
  ctx = None 
)

Definition at line 11242 of file z3py.py.

11242def CharToInt(ch, ctx=None):
11243 ch = _coerce_char(ch, ctx)
11244 return ch.to_int()
11245

◆ CharVal()

CharVal (   ch,
  ctx = None 
)

Definition at line 11225 of file z3py.py.

11225def CharVal(ch, ctx=None):
11226 ctx = _get_ctx(ctx)
11227 if isinstance(ch, str):
11228 ch = ord(ch)
11229 if not isinstance(ch, int):
11230 raise Z3Exception("character value should be an ordinal")
11231 return _to_expr_ref(Z3_mk_char(ctx.ref(), ch), ctx)
11232
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 11675 of file z3py.py.

11675def Complement(re):
11676 """Create the complement regular expression."""
11677 return ReRef(Z3_mk_re_complement(re.ctx_ref(), re.as_ast()), re.ctx)
11678
11679
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 4236 of file z3py.py.

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

9118def Cond(p, t1, t2, ctx=None):
9119 """Return a tactic that applies tactic `t1` to a goal if probe `p` evaluates to true, and `t2` otherwise.
9120
9121 >>> t = Cond(Probe('is-qfnra'), Tactic('qfnra'), Tactic('smt'))
9122 """
9123 p = _to_probe(p, ctx)
9124 t1 = _to_tactic(t1, ctx)
9125 t2 = _to_tactic(t2, ctx)
9126 return Tactic(Z3_tactic_cond(t1.ctx.ref(), p.probe, t1.tactic, t2.tactic), t1.ctx)
9127
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 11420 of file z3py.py.

11420def Contains(a, b):
11421 """Check if 'a' contains 'b'
11422 >>> s1 = Contains("abc", "ab")
11423 >>> simplify(s1)
11424 True
11425 >>> s2 = Contains("abc", "bc")
11426 >>> simplify(s2)
11427 True
11428 >>> x, y, z = Strings('x y z')
11429 >>> s3 = Contains(Concat(x,y,z), y)
11430 >>> simplify(s3)
11431 True
11432 """
11433 ctx = _get_ctx2(a, b)
11434 a = _coerce_seq(a, ctx)
11435 b = _coerce_seq(b, ctx)
11436 return BoolRef(Z3_mk_seq_contains(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
11437
11438
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 5328 of file z3py.py.

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

5554def DatatypeSort(name, params=None, ctx=None):
5555 """Create a reference to a sort that was declared, or will be declared, as a recursive datatype.
5556
5557 Args:
5558 name: name of the datatype sort
5559 params: optional list/tuple of sort parameters for parametric datatypes
5560 ctx: Z3 context (optional)
5561
5562 Example:
5563 >>> # Non-parametric datatype
5564 >>> TreeRef = DatatypeSort('Tree')
5565 >>> # Parametric datatype with one parameter
5566 >>> ListIntRef = DatatypeSort('List', [IntSort()])
5567 >>> # Parametric datatype with multiple parameters
5568 >>> PairRef = DatatypeSort('Pair', [IntSort(), BoolSort()])
5569 """
5570 ctx = _get_ctx(ctx)
5571 if params is None or len(params) == 0:
5572 return DatatypeSortRef(Z3_mk_datatype_sort(ctx.ref(), to_symbol(name, ctx), 0, (Sort * 0)()), ctx)
5573 else:
5574 _params = (Sort * len(params))()
5575 for i in range(len(params)):
5576 _params[i] = params[i].ast
5577 return DatatypeSortRef(Z3_mk_datatype_sort(ctx.ref(), to_symbol(name, ctx), len(params), _params), ctx)
5578
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 4956 of file z3py.py.

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

◆ describe_probes()

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

Definition at line 9039 of file z3py.py.

9039def describe_probes():
9040 """Display a (tabular) description of all available probes in Z3."""
9041 if in_html_mode():
9042 even = True
9043 print('<table border="1" cellpadding="2" cellspacing="0">')
9044 for p in probes():
9045 if even:
9046 print('<tr style="background-color:#CFCFCF">')
9047 even = False
9048 else:
9049 print("<tr>")
9050 even = True
9051 print("<td>%s</td><td>%s</td></tr>" % (p, insert_line_breaks(probe_description(p), 40)))
9052 print("</table>")
9053 else:
9054 for p in probes():
9055 print("%s : %s" % (p, probe_description(p)))
9056
9057

◆ describe_tactics()

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

Definition at line 8833 of file z3py.py.

8833def describe_tactics():
8834 """Display a (tabular) description of all available tactics in Z3."""
8835 if in_html_mode():
8836 even = True
8837 print('<table border="1" cellpadding="2" cellspacing="0">')
8838 for t in tactics():
8839 if even:
8840 print('<tr style="background-color:#CFCFCF">')
8841 even = False
8842 else:
8843 print("<tr>")
8844 even = True
8845 print("<td>%s</td><td>%s</td></tr>" % (t, insert_line_breaks(tactic_description(t), 40)))
8846 print("</table>")
8847 else:
8848 for t in tactics():
8849 print("%s : %s" % (t, tactic_description(t)))
8850
8851

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

11725def Diff(a, b, ctx=None):
11726 """Create the difference regular expression
11727 """
11728 if z3_debug():
11729 _z3_assert(is_expr(a), "expression expected")
11730 _z3_assert(is_expr(b), "expression expected")
11731 return ReRef(Z3_mk_re_diff(a.ctx_ref(), a.ast, b.ast), a.ctx)
11732
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 5591 of file z3py.py.

5591def DisjointSum(name, sorts, ctx=None):
5592 """Create a named tagged union sort base on a set of underlying sorts
5593 Example:
5594 >>> sum, ((inject0, extract0), (inject1, extract1)) = DisjointSum("+", [IntSort(), StringSort()])
5595 """
5596 sum = Datatype(name, ctx)
5597 for i in range(len(sorts)):
5598 sum.declare("inject%d" % i, ("project%d" % i, sorts[i]))
5599 sum = sum.create()
5600 return sum, [(sum.constructor(i), sum.accessor(i, 0)) for i in range(len(sorts))]
5601
5602

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

11350def Empty(s):
11351 """Create the empty sequence of the given sort
11352 >>> e = Empty(StringSort())
11353 >>> e2 = StringVal("")
11354 >>> print(e.eq(e2))
11355 True
11356 >>> e3 = Empty(SeqSort(IntSort()))
11357 >>> print(e3)
11358 Empty(Seq(Int))
11359 >>> e4 = Empty(ReSort(SeqSort(IntSort())))
11360 >>> print(e4)
11361 Empty(ReSort(Seq(Int)))
11362 """
11363 if isinstance(s, SeqSortRef):
11364 return SeqRef(Z3_mk_seq_empty(s.ctx_ref(), s.ast), s.ctx)
11365 if isinstance(s, ReSortRef):
11366 return ReRef(Z3_mk_re_empty(s.ctx_ref(), s.ast), s.ctx)
11367 raise Z3Exception("Non-sequence, non-regular expression sort passed to Empty")
11368
11369
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 5092 of file z3py.py.

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

11844def ensure_prop_closures():
11845 global _prop_closures
11846 if _prop_closures is None:
11847 _prop_closures = PropClosures()
11848
11849

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

5603def EnumSort(name, values, ctx=None):
5604 """Return a new enumeration sort named `name` containing the given values.
5605
5606 The result is a pair (sort, list of constants).
5607 Example:
5608 >>> Color, (red, green, blue) = EnumSort('Color', ['red', 'green', 'blue'])
5609 """
5610 if z3_debug():
5611 _z3_assert(isinstance(name, str), "Name must be a string")
5612 _z3_assert(all([isinstance(v, str) for v in values]), "Enumeration sort values must be strings")
5613 _z3_assert(len(values) > 0, "At least one value expected")
5614 ctx = _get_ctx(ctx)
5615 num = len(values)
5616 _val_names = (Symbol * num)()
5617 for i in range(num):
5618 _val_names[i] = to_symbol(values[i], ctx)
5619 _values = (FuncDecl * num)()
5620 _testers = (FuncDecl * num)()
5621 name = to_symbol(name, ctx)
5622 S = DatatypeSortRef(Z3_mk_enumeration_sort(ctx.ref(), name, num, _val_names, _values, _testers), ctx)
5623 V = []
5624 for i in range(num):
5625 V.append(FuncDeclRef(_values[i], ctx))
5626 V = [a() for a in V]
5627 return S, V
5628
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 5045 of file z3py.py.

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

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

9076def FailIf(p, ctx=None):
9077 """Return a tactic that fails if the probe `p` evaluates to true.
9078 Otherwise, it returns the input goal unmodified.
9079
9080 In the following example, the tactic applies 'simplify' if and only if there are
9081 more than 2 constraints in the goal.
9082
9083 >>> t = OrElse(FailIf(Probe('size') > 2), Tactic('simplify'))
9084 >>> x, y = Ints('x y')
9085 >>> g = Goal()
9086 >>> g.add(x > 0)
9087 >>> g.add(y > 0)
9088 >>> t(g)
9089 [[x > 0, y > 0]]
9090 >>> g.add(x == y + 1)
9091 >>> t(g)
9092 [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
9093 """
9094 p = _to_probe(p, ctx)
9095 return Tactic(Z3_tactic_fail_if(p.ctx.ref(), p.probe), p.ctx)
9096
9097
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 8005 of file z3py.py.

8005def FiniteDomainSort(name, sz, ctx=None):
8006 """Create a named finite domain sort of a given size sz"""
8007 if not isinstance(name, Symbol):
8008 name = to_symbol(name)
8009 ctx = _get_ctx(ctx)
8010 return FiniteDomainSortRef(Z3_mk_finite_domain_sort(ctx.ref(), name, sz), ctx)
8011
8012
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 8075 of file z3py.py.

8075def FiniteDomainVal(val, sort, ctx=None):
8076 """Return a Z3 finite-domain value. If `ctx=None`, then the global context is used.
8077
8078 >>> s = FiniteDomainSort('S', 256)
8079 >>> FiniteDomainVal(255, s)
8080 255
8081 >>> FiniteDomainVal('100', s)
8082 100
8083 """
8084 if z3_debug():
8085 _z3_assert(is_finite_domain_sort(sort), "Expected finite-domain sort")
8086 ctx = sort.ctx
8087 return FiniteDomainNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), sort.ast), ctx)
8088
8089

◆ Float128()

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

Definition at line 9804 of file z3py.py.

9804def Float128(ctx=None):
9805 """Floating-point 128-bit (quadruple) sort."""
9806 ctx = _get_ctx(ctx)
9807 return FPSortRef(Z3_mk_fpa_sort_128(ctx.ref()), ctx)
9808
9809
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 9768 of file z3py.py.

9768def Float16(ctx=None):
9769 """Floating-point 16-bit (half) sort."""
9770 ctx = _get_ctx(ctx)
9771 return FPSortRef(Z3_mk_fpa_sort_16(ctx.ref()), ctx)
9772
9773
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 9780 of file z3py.py.

9780def Float32(ctx=None):
9781 """Floating-point 32-bit (single) sort."""
9782 ctx = _get_ctx(ctx)
9783 return FPSortRef(Z3_mk_fpa_sort_32(ctx.ref()), ctx)
9784
9785
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 9792 of file z3py.py.

9792def Float64(ctx=None):
9793 """Floating-point 64-bit (double) sort."""
9794 ctx = _get_ctx(ctx)
9795 return FPSortRef(Z3_mk_fpa_sort_64(ctx.ref()), ctx)
9796
9797
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 9798 of file z3py.py.

9798def FloatDouble(ctx=None):
9799 """Floating-point 64-bit (double) sort."""
9800 ctx = _get_ctx(ctx)
9801 return FPSortRef(Z3_mk_fpa_sort_double(ctx.ref()), ctx)
9802
9803
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 9774 of file z3py.py.

9774def FloatHalf(ctx=None):
9775 """Floating-point 16-bit (half) sort."""
9776 ctx = _get_ctx(ctx)
9777 return FPSortRef(Z3_mk_fpa_sort_half(ctx.ref()), ctx)
9778
9779
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 9810 of file z3py.py.

9810def FloatQuadruple(ctx=None):
9811 """Floating-point 128-bit (quadruple) sort."""
9812 ctx = _get_ctx(ctx)
9813 return FPSortRef(Z3_mk_fpa_sort_quadruple(ctx.ref()), ctx)
9814
9815
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 9786 of file z3py.py.

9786def FloatSingle(ctx=None):
9787 """Floating-point 32-bit (single) sort."""
9788 ctx = _get_ctx(ctx)
9789 return FPSortRef(Z3_mk_fpa_sort_single(ctx.ref()), ctx)
9790
9791
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 10446 of file z3py.py.

10446def FP(name, fpsort, ctx=None):
10447 """Return a floating-point constant named `name`.
10448 `fpsort` is the floating-point sort.
10449 If `ctx=None`, then the global context is used.
10450
10451 >>> x = FP('x', FPSort(8, 24))
10452 >>> is_fp(x)
10453 True
10454 >>> x.ebits()
10455 8
10456 >>> x.sort()
10457 FPSort(8, 24)
10458 >>> word = FPSort(8, 24)
10459 >>> x2 = FP('x', word)
10460 >>> eq(x, x2)
10461 True
10462 """
10463 if isinstance(fpsort, FPSortRef) and ctx is None:
10464 ctx = fpsort.ctx
10465 else:
10466 ctx = _get_ctx(ctx)
10467 return FPRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), fpsort.ast), ctx)
10468
10469

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

10489def fpAbs(a, ctx=None):
10490 """Create a Z3 floating-point absolute value expression.
10491
10492 >>> s = FPSort(8, 24)
10493 >>> rm = RNE()
10494 >>> x = FPVal(1.0, s)
10495 >>> fpAbs(x)
10496 fpAbs(1)
10497 >>> y = FPVal(-20.0, s)
10498 >>> y
10499 -1.25*(2**4)
10500 >>> fpAbs(y)
10501 fpAbs(-1.25*(2**4))
10502 >>> fpAbs(-1.25*(2**4))
10503 fpAbs(-1.25*(2**4))
10504 >>> fpAbs(x).sort()
10505 FPSort(8, 24)
10506 """
10507 ctx = _get_ctx(ctx)
10508 [a] = _coerce_fp_expr_list([a], ctx)
10509 return FPRef(Z3_mk_fpa_abs(ctx.ref(), a.as_ast()), ctx)
10510
10511
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 10580 of file z3py.py.

10580def fpAdd(rm, a, b, ctx=None):
10581 """Create a Z3 floating-point addition expression.
10582
10583 >>> s = FPSort(8, 24)
10584 >>> rm = RNE()
10585 >>> x = FP('x', s)
10586 >>> y = FP('y', s)
10587 >>> fpAdd(rm, x, y)
10588 x + y
10589 >>> fpAdd(RTZ(), x, y) # default rounding mode is RTZ
10590 fpAdd(RTZ(), x, y)
10591 >>> fpAdd(rm, x, y).sort()
10592 FPSort(8, 24)
10593 """
10594 return _mk_fp_bin(Z3_mk_fpa_add, rm, a, b, ctx)
10595
10596

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

10902def fpBVToFP(v, sort, ctx=None):
10903 """Create a Z3 floating-point conversion expression that represents the
10904 conversion from a bit-vector term to a floating-point term.
10905
10906 >>> x_bv = BitVecVal(0x3F800000, 32)
10907 >>> x_fp = fpBVToFP(x_bv, Float32())
10908 >>> x_fp
10909 fpToFP(1065353216)
10910 >>> simplify(x_fp)
10911 1
10912 """
10913 _z3_assert(is_bv(v), "First argument must be a Z3 bit-vector expression")
10914 _z3_assert(is_fp_sort(sort), "Second argument must be a Z3 floating-point sort.")
10915 ctx = _get_ctx(ctx)
10916 return FPRef(Z3_mk_fpa_to_fp_bv(ctx.ref(), v.ast, sort.ast), ctx)
10917
10918
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 10627 of file z3py.py.

10627def fpDiv(rm, a, b, ctx=None):
10628 """Create a Z3 floating-point division expression.
10629
10630 >>> s = FPSort(8, 24)
10631 >>> rm = RNE()
10632 >>> x = FP('x', s)
10633 >>> y = FP('y', s)
10634 >>> fpDiv(rm, x, y)
10635 x / y
10636 >>> fpDiv(rm, x, y).sort()
10637 FPSort(8, 24)
10638 """
10639 return _mk_fp_bin(Z3_mk_fpa_div, rm, a, b, ctx)
10640
10641

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

10810def fpEQ(a, b, ctx=None):
10811 """Create the Z3 floating-point expression `fpEQ(other, self)`.
10812
10813 >>> x, y = FPs('x y', FPSort(8, 24))
10814 >>> fpEQ(x, y)
10815 fpEQ(x, y)
10816 >>> fpEQ(x, y).sexpr()
10817 '(fp.eq x y)'
10818 """
10819 return _mk_fp_bin_pred(Z3_mk_fpa_eq, a, b, ctx)
10820
10821

◆ fpFMA()

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

Definition at line 10686 of file z3py.py.

10686def fpFMA(rm, a, b, c, ctx=None):
10687 """Create a Z3 floating-point fused multiply-add expression.
10688 """
10689 return _mk_fp_tern(Z3_mk_fpa_fma, rm, a, b, c, ctx)
10690
10691

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

10834def fpFP(sgn, exp, sig, ctx=None):
10835 """Create the Z3 floating-point value `fpFP(sgn, sig, exp)` from the three bit-vectors sgn, sig, and exp.
10836
10837 >>> s = FPSort(8, 24)
10838 >>> x = fpFP(BitVecVal(1, 1), BitVecVal(2**7-1, 8), BitVecVal(2**22, 23))
10839 >>> print(x)
10840 fpFP(1, 127, 4194304)
10841 >>> xv = FPVal(-1.5, s)
10842 >>> print(xv)
10843 -1.5
10844 >>> slvr = Solver()
10845 >>> slvr.add(fpEQ(x, xv))
10846 >>> slvr.check()
10847 sat
10848 >>> xv = FPVal(+1.5, s)
10849 >>> print(xv)
10850 1.5
10851 >>> slvr = Solver()
10852 >>> slvr.add(fpEQ(x, xv))
10853 >>> slvr.check()
10854 unsat
10855 """
10856 _z3_assert(is_bv(sgn) and is_bv(exp) and is_bv(sig), "sort mismatch")
10857 _z3_assert(sgn.sort().size() == 1, "sort mismatch")
10858 ctx = _get_ctx(ctx)
10859 _z3_assert(ctx == sgn.ctx == exp.ctx == sig.ctx, "context mismatch")
10860 return FPRef(Z3_mk_fpa_fp(ctx.ref(), sgn.ast, exp.ast, sig.ast), ctx)
10861
10862
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 10919 of file z3py.py.

10919def fpFPToFP(rm, v, sort, ctx=None):
10920 """Create a Z3 floating-point conversion expression that represents the
10921 conversion from a floating-point term to a floating-point term of different precision.
10922
10923 >>> x_sgl = FPVal(1.0, Float32())
10924 >>> x_dbl = fpFPToFP(RNE(), x_sgl, Float64())
10925 >>> x_dbl
10926 fpToFP(RNE(), 1)
10927 >>> simplify(x_dbl)
10928 1
10929 >>> x_dbl.sort()
10930 FPSort(11, 53)
10931 """
10932 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10933 _z3_assert(is_fp(v), "Second argument must be a Z3 floating-point expression.")
10934 _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
10935 ctx = _get_ctx(ctx)
10936 return FPRef(Z3_mk_fpa_to_fp_float(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
10937
10938
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 10798 of file z3py.py.

10798def fpGEQ(a, b, ctx=None):
10799 """Create the Z3 floating-point expression `other >= self`.
10800
10801 >>> x, y = FPs('x y', FPSort(8, 24))
10802 >>> fpGEQ(x, y)
10803 x >= y
10804 >>> (x >= y).sexpr()
10805 '(fp.geq x y)'
10806 """
10807 return _mk_fp_bin_pred(Z3_mk_fpa_geq, a, b, ctx)
10808
10809

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

10786def fpGT(a, b, ctx=None):
10787 """Create the Z3 floating-point expression `other > self`.
10788
10789 >>> x, y = FPs('x y', FPSort(8, 24))
10790 >>> fpGT(x, y)
10791 x > y
10792 >>> (x > y).sexpr()
10793 '(fp.gt x y)'
10794 """
10795 return _mk_fp_bin_pred(Z3_mk_fpa_gt, a, b, ctx)
10796
10797

◆ fpInfinity()

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

Definition at line 10374 of file z3py.py.

10374def fpInfinity(s, negative):
10375 """Create a Z3 floating-point +oo or -oo term."""
10376 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10377 _z3_assert(isinstance(negative, bool), "expected Boolean flag")
10378 return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, negative), s.ctx)
10379
10380
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 10716 of file z3py.py.

10716def fpIsInf(a, ctx=None):
10717 """Create a Z3 floating-point isInfinite expression.
10718
10719 >>> s = FPSort(8, 24)
10720 >>> x = FP('x', s)
10721 >>> fpIsInf(x)
10722 fpIsInf(x)
10723 """
10724 return _mk_fp_unary_pred(Z3_mk_fpa_is_infinite, a, ctx)
10725
10726

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

10704def fpIsNaN(a, ctx=None):
10705 """Create a Z3 floating-point isNaN expression.
10706
10707 >>> s = FPSort(8, 24)
10708 >>> x = FP('x', s)
10709 >>> y = FP('y', s)
10710 >>> fpIsNaN(x)
10711 fpIsNaN(x)
10712 """
10713 return _mk_fp_unary_pred(Z3_mk_fpa_is_nan, a, ctx)
10714
10715

◆ fpIsNegative()

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

Definition at line 10745 of file z3py.py.

10745def fpIsNegative(a, ctx=None):
10746 """Create a Z3 floating-point isNegative expression.
10747 """
10748 return _mk_fp_unary_pred(Z3_mk_fpa_is_negative, a, ctx)
10749
10750

◆ fpIsNormal()

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

Definition at line 10733 of file z3py.py.

10733def fpIsNormal(a, ctx=None):
10734 """Create a Z3 floating-point isNormal expression.
10735 """
10736 return _mk_fp_unary_pred(Z3_mk_fpa_is_normal, a, ctx)
10737
10738

◆ fpIsPositive()

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

Definition at line 10751 of file z3py.py.

10751def fpIsPositive(a, ctx=None):
10752 """Create a Z3 floating-point isPositive expression.
10753 """
10754 return _mk_fp_unary_pred(Z3_mk_fpa_is_positive, a, ctx)
10755
10756

◆ fpIsSubnormal()

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

Definition at line 10739 of file z3py.py.

10739def fpIsSubnormal(a, ctx=None):
10740 """Create a Z3 floating-point isSubnormal expression.
10741 """
10742 return _mk_fp_unary_pred(Z3_mk_fpa_is_subnormal, a, ctx)
10743
10744

◆ fpIsZero()

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

Definition at line 10727 of file z3py.py.

10727def fpIsZero(a, ctx=None):
10728 """Create a Z3 floating-point isZero expression.
10729 """
10730 return _mk_fp_unary_pred(Z3_mk_fpa_is_zero, a, ctx)
10731
10732

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

10774def fpLEQ(a, b, ctx=None):
10775 """Create the Z3 floating-point expression `other <= self`.
10776
10777 >>> x, y = FPs('x y', FPSort(8, 24))
10778 >>> fpLEQ(x, y)
10779 x <= y
10780 >>> (x <= y).sexpr()
10781 '(fp.leq x y)'
10782 """
10783 return _mk_fp_bin_pred(Z3_mk_fpa_leq, a, b, ctx)
10784
10785

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

10762def fpLT(a, b, ctx=None):
10763 """Create the Z3 floating-point expression `other < self`.
10764
10765 >>> x, y = FPs('x y', FPSort(8, 24))
10766 >>> fpLT(x, y)
10767 x < y
10768 >>> (x < y).sexpr()
10769 '(fp.lt x y)'
10770 """
10771 return _mk_fp_bin_pred(Z3_mk_fpa_lt, a, b, ctx)
10772
10773

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

10671def fpMax(a, b, ctx=None):
10672 """Create a Z3 floating-point maximum expression.
10673
10674 >>> s = FPSort(8, 24)
10675 >>> rm = RNE()
10676 >>> x = FP('x', s)
10677 >>> y = FP('y', s)
10678 >>> fpMax(x, y)
10679 fpMax(x, y)
10680 >>> fpMax(x, y).sort()
10681 FPSort(8, 24)
10682 """
10683 return _mk_fp_bin_norm(Z3_mk_fpa_max, a, b, ctx)
10684
10685

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

10656def fpMin(a, b, ctx=None):
10657 """Create a Z3 floating-point minimum expression.
10658
10659 >>> s = FPSort(8, 24)
10660 >>> rm = RNE()
10661 >>> x = FP('x', s)
10662 >>> y = FP('y', s)
10663 >>> fpMin(x, y)
10664 fpMin(x, y)
10665 >>> fpMin(x, y).sort()
10666 FPSort(8, 24)
10667 """
10668 return _mk_fp_bin_norm(Z3_mk_fpa_min, a, b, ctx)
10669
10670

◆ fpMinusInfinity()

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

Definition at line 10368 of file z3py.py.

10368def fpMinusInfinity(s):
10369 """Create a Z3 floating-point -oo term."""
10370 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10371 return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, True), s.ctx)
10372
10373

◆ fpMinusZero()

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

Definition at line 10387 of file z3py.py.

10387def fpMinusZero(s):
10388 """Create a Z3 floating-point -0.0 term."""
10389 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10390 return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, True), s.ctx)
10391
10392
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 10612 of file z3py.py.

10612def fpMul(rm, a, b, ctx=None):
10613 """Create a Z3 floating-point multiplication expression.
10614
10615 >>> s = FPSort(8, 24)
10616 >>> rm = RNE()
10617 >>> x = FP('x', s)
10618 >>> y = FP('y', s)
10619 >>> fpMul(rm, x, y)
10620 x * y
10621 >>> fpMul(rm, x, y).sort()
10622 FPSort(8, 24)
10623 """
10624 return _mk_fp_bin(Z3_mk_fpa_mul, rm, a, b, ctx)
10625
10626

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

10334def fpNaN(s):
10335 """Create a Z3 floating-point NaN term.
10336
10337 >>> s = FPSort(8, 24)
10338 >>> set_fpa_pretty(True)
10339 >>> fpNaN(s)
10340 NaN
10341 >>> pb = get_fpa_pretty()
10342 >>> set_fpa_pretty(False)
10343 >>> fpNaN(s)
10344 fpNaN(FPSort(8, 24))
10345 >>> set_fpa_pretty(pb)
10346 """
10347 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10348 return FPNumRef(Z3_mk_fpa_nan(s.ctx_ref(), s.ast), s.ctx)
10349
10350
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 10512 of file z3py.py.

10512def fpNeg(a, ctx=None):
10513 """Create a Z3 floating-point addition expression.
10514
10515 >>> s = FPSort(8, 24)
10516 >>> rm = RNE()
10517 >>> x = FP('x', s)
10518 >>> fpNeg(x)
10519 -x
10520 >>> fpNeg(x).sort()
10521 FPSort(8, 24)
10522 """
10523 ctx = _get_ctx(ctx)
10524 [a] = _coerce_fp_expr_list([a], ctx)
10525 return FPRef(Z3_mk_fpa_neg(ctx.ref(), a.as_ast()), ctx)
10526
10527
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 10822 of file z3py.py.

10822def fpNEQ(a, b, ctx=None):
10823 """Create the Z3 floating-point expression `Not(fpEQ(other, self))`.
10824
10825 >>> x, y = FPs('x y', FPSort(8, 24))
10826 >>> fpNEQ(x, y)
10827 Not(fpEQ(x, y))
10828 >>> (x != y).sexpr()
10829 '(distinct x y)'
10830 """
10831 return Not(fpEQ(a, b, ctx))
10832
10833

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

10351def fpPlusInfinity(s):
10352 """Create a Z3 floating-point +oo term.
10353
10354 >>> s = FPSort(8, 24)
10355 >>> pb = get_fpa_pretty()
10356 >>> set_fpa_pretty(True)
10357 >>> fpPlusInfinity(s)
10358 +oo
10359 >>> set_fpa_pretty(False)
10360 >>> fpPlusInfinity(s)
10361 fpPlusInfinity(FPSort(8, 24))
10362 >>> set_fpa_pretty(pb)
10363 """
10364 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10365 return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, False), s.ctx)
10366
10367

◆ fpPlusZero()

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

Definition at line 10381 of file z3py.py.

10381def fpPlusZero(s):
10382 """Create a Z3 floating-point +0.0 term."""
10383 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10384 return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, False), s.ctx)
10385
10386

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

10939def fpRealToFP(rm, v, sort, ctx=None):
10940 """Create a Z3 floating-point conversion expression that represents the
10941 conversion from a real term to a floating-point term.
10942
10943 >>> x_r = RealVal(1.5)
10944 >>> x_fp = fpRealToFP(RNE(), x_r, Float32())
10945 >>> x_fp
10946 fpToFP(RNE(), 3/2)
10947 >>> simplify(x_fp)
10948 1.5
10949 """
10950 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10951 _z3_assert(is_real(v), "Second argument must be a Z3 expression or real sort.")
10952 _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
10953 ctx = _get_ctx(ctx)
10954 return FPRef(Z3_mk_fpa_to_fp_real(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
10955
10956
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 10642 of file z3py.py.

10642def fpRem(a, b, ctx=None):
10643 """Create a Z3 floating-point remainder expression.
10644
10645 >>> s = FPSort(8, 24)
10646 >>> x = FP('x', s)
10647 >>> y = FP('y', s)
10648 >>> fpRem(x, y)
10649 fpRem(x, y)
10650 >>> fpRem(x, y).sort()
10651 FPSort(8, 24)
10652 """
10653 return _mk_fp_bin_norm(Z3_mk_fpa_rem, a, b, ctx)
10654
10655

◆ fpRoundToIntegral()

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

Definition at line 10698 of file z3py.py.

10698def fpRoundToIntegral(rm, a, ctx=None):
10699 """Create a Z3 floating-point roundToIntegral expression.
10700 """
10701 return _mk_fp_unary(Z3_mk_fpa_round_to_integral, rm, a, ctx)
10702
10703

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

10470def FPs(names, fpsort, ctx=None):
10471 """Return an array of floating-point constants.
10472
10473 >>> x, y, z = FPs('x y z', FPSort(8, 24))
10474 >>> x.sort()
10475 FPSort(8, 24)
10476 >>> x.sbits()
10477 24
10478 >>> x.ebits()
10479 8
10480 >>> fpMul(RNE(), fpAdd(RNE(), x, y), z)
10481 (x + y) * z
10482 """
10483 ctx = _get_ctx(ctx)
10484 if isinstance(names, str):
10485 names = names.split(" ")
10486 return [FP(name, fpsort, ctx) for name in names]
10487
10488

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

10957def fpSignedToFP(rm, v, sort, ctx=None):
10958 """Create a Z3 floating-point conversion expression that represents the
10959 conversion from a signed bit-vector term (encoding an integer) to a floating-point term.
10960
10961 >>> x_signed = BitVecVal(-5, BitVecSort(32))
10962 >>> x_fp = fpSignedToFP(RNE(), x_signed, Float32())
10963 >>> x_fp
10964 fpToFP(RNE(), 4294967291)
10965 >>> simplify(x_fp)
10966 -1.25*(2**2)
10967 """
10968 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10969 _z3_assert(is_bv(v), "Second argument must be a Z3 bit-vector expression")
10970 _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
10971 ctx = _get_ctx(ctx)
10972 return FPRef(Z3_mk_fpa_to_fp_signed(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
10973
10974
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 10275 of file z3py.py.

10275def FPSort(ebits, sbits, ctx=None):
10276 """Return a Z3 floating-point sort of the given sizes. If `ctx=None`, then the global context is used.
10277
10278 >>> Single = FPSort(8, 24)
10279 >>> Double = FPSort(11, 53)
10280 >>> Single
10281 FPSort(8, 24)
10282 >>> x = Const('x', Single)
10283 >>> eq(x, FP('x', FPSort(8, 24)))
10284 True
10285 """
10286 ctx = _get_ctx(ctx)
10287 return FPSortRef(Z3_mk_fpa_sort(ctx.ref(), ebits, sbits), ctx)
10288
10289
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 10692 of file z3py.py.

10692def fpSqrt(rm, a, ctx=None):
10693 """Create a Z3 floating-point square root expression.
10694 """
10695 return _mk_fp_unary(Z3_mk_fpa_sqrt, rm, a, ctx)
10696
10697

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

10597def fpSub(rm, a, b, ctx=None):
10598 """Create a Z3 floating-point subtraction expression.
10599
10600 >>> s = FPSort(8, 24)
10601 >>> rm = RNE()
10602 >>> x = FP('x', s)
10603 >>> y = FP('y', s)
10604 >>> fpSub(rm, x, y)
10605 x - y
10606 >>> fpSub(rm, x, y).sort()
10607 FPSort(8, 24)
10608 """
10609 return _mk_fp_bin(Z3_mk_fpa_sub, rm, a, b, ctx)
10610
10611

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

10863def fpToFP(a1, a2=None, a3=None, ctx=None):
10864 """Create a Z3 floating-point conversion expression from other term sorts
10865 to floating-point.
10866
10867 From a bit-vector term in IEEE 754-2008 format:
10868 >>> x = FPVal(1.0, Float32())
10869 >>> x_bv = fpToIEEEBV(x)
10870 >>> simplify(fpToFP(x_bv, Float32()))
10871 1
10872
10873 From a floating-point term with different precision:
10874 >>> x = FPVal(1.0, Float32())
10875 >>> x_db = fpToFP(RNE(), x, Float64())
10876 >>> x_db.sort()
10877 FPSort(11, 53)
10878
10879 From a real term:
10880 >>> x_r = RealVal(1.5)
10881 >>> simplify(fpToFP(RNE(), x_r, Float32()))
10882 1.5
10883
10884 From a signed bit-vector term:
10885 >>> x_signed = BitVecVal(-5, BitVecSort(32))
10886 >>> simplify(fpToFP(RNE(), x_signed, Float32()))
10887 -1.25*(2**2)
10888 """
10889 ctx = _get_ctx(ctx)
10890 if is_bv(a1) and is_fp_sort(a2):
10891 return FPRef(Z3_mk_fpa_to_fp_bv(ctx.ref(), a1.ast, a2.ast), ctx)
10892 elif is_fprm(a1) and is_fp(a2) and is_fp_sort(a3):
10893 return FPRef(Z3_mk_fpa_to_fp_float(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
10894 elif is_fprm(a1) and is_real(a2) and is_fp_sort(a3):
10895 return FPRef(Z3_mk_fpa_to_fp_real(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
10896 elif is_fprm(a1) and is_bv(a2) and is_fp_sort(a3):
10897 return FPRef(Z3_mk_fpa_to_fp_signed(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
10898 else:
10899 raise Z3Exception("Unsupported combination of arguments for conversion to floating-point term.")
10900
10901

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

10993def fpToFPUnsigned(rm, x, s, ctx=None):
10994 """Create a Z3 floating-point conversion expression, from unsigned bit-vector to floating-point expression."""
10995 if z3_debug():
10996 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
10997 _z3_assert(is_bv(x), "Second argument must be a Z3 bit-vector expression")
10998 _z3_assert(is_fp_sort(s), "Third argument must be Z3 floating-point sort")
10999 ctx = _get_ctx(ctx)
11000 return FPRef(Z3_mk_fpa_to_fp_unsigned(ctx.ref(), rm.ast, x.ast, s.ast), ctx)
11001
11002
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 11067 of file z3py.py.

11067def fpToIEEEBV(x, ctx=None):
11068 """\brief Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.
11069
11070 The size of the resulting bit-vector is automatically determined.
11071
11072 Note that IEEE 754-2008 allows multiple different representations of NaN. This conversion
11073 knows only one NaN and it will always produce the same bit-vector representation of
11074 that NaN.
11075
11076 >>> x = FP('x', FPSort(8, 24))
11077 >>> y = fpToIEEEBV(x)
11078 >>> print(is_fp(x))
11079 True
11080 >>> print(is_bv(y))
11081 True
11082 >>> print(is_fp(y))
11083 False
11084 >>> print(is_bv(x))
11085 False
11086 """
11087 if z3_debug():
11088 _z3_assert(is_fp(x), "First argument must be a Z3 floating-point expression")
11089 ctx = _get_ctx(ctx)
11090 return BitVecRef(Z3_mk_fpa_to_ieee_bv(ctx.ref(), x.ast), ctx)
11091
11092
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 11047 of file z3py.py.

11047def fpToReal(x, ctx=None):
11048 """Create a Z3 floating-point conversion expression, from floating-point expression to real.
11049
11050 >>> x = FP('x', FPSort(8, 24))
11051 >>> y = fpToReal(x)
11052 >>> print(is_fp(x))
11053 True
11054 >>> print(is_real(y))
11055 True
11056 >>> print(is_fp(y))
11057 False
11058 >>> print(is_real(x))
11059 False
11060 """
11061 if z3_debug():
11062 _z3_assert(is_fp(x), "First argument must be a Z3 floating-point expression")
11063 ctx = _get_ctx(ctx)
11064 return ArithRef(Z3_mk_fpa_to_real(ctx.ref(), x.ast), ctx)
11065
11066
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 11003 of file z3py.py.

11003def fpToSBV(rm, x, s, ctx=None):
11004 """Create a Z3 floating-point conversion expression, from floating-point expression to signed bit-vector.
11005
11006 >>> x = FP('x', FPSort(8, 24))
11007 >>> y = fpToSBV(RTZ(), x, BitVecSort(32))
11008 >>> print(is_fp(x))
11009 True
11010 >>> print(is_bv(y))
11011 True
11012 >>> print(is_fp(y))
11013 False
11014 >>> print(is_bv(x))
11015 False
11016 """
11017 if z3_debug():
11018 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
11019 _z3_assert(is_fp(x), "Second argument must be a Z3 floating-point expression")
11020 _z3_assert(is_bv_sort(s), "Third argument must be Z3 bit-vector sort")
11021 ctx = _get_ctx(ctx)
11022 return BitVecRef(Z3_mk_fpa_to_sbv(ctx.ref(), rm.ast, x.ast, s.size()), ctx)
11023
11024
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 11025 of file z3py.py.

11025def fpToUBV(rm, x, s, ctx=None):
11026 """Create a Z3 floating-point conversion expression, from floating-point expression to unsigned bit-vector.
11027
11028 >>> x = FP('x', FPSort(8, 24))
11029 >>> y = fpToUBV(RTZ(), x, BitVecSort(32))
11030 >>> print(is_fp(x))
11031 True
11032 >>> print(is_bv(y))
11033 True
11034 >>> print(is_fp(y))
11035 False
11036 >>> print(is_bv(x))
11037 False
11038 """
11039 if z3_debug():
11040 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
11041 _z3_assert(is_fp(x), "Second argument must be a Z3 floating-point expression")
11042 _z3_assert(is_bv_sort(s), "Third argument must be Z3 bit-vector sort")
11043 ctx = _get_ctx(ctx)
11044 return BitVecRef(Z3_mk_fpa_to_ubv(ctx.ref(), rm.ast, x.ast, s.size()), ctx)
11045
11046
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 10975 of file z3py.py.

10975def fpUnsignedToFP(rm, v, sort, ctx=None):
10976 """Create a Z3 floating-point conversion expression that represents the
10977 conversion from an unsigned bit-vector term (encoding an integer) to a floating-point term.
10978
10979 >>> x_signed = BitVecVal(-5, BitVecSort(32))
10980 >>> x_fp = fpUnsignedToFP(RNE(), x_signed, Float32())
10981 >>> x_fp
10982 fpToFPUnsigned(RNE(), 4294967291)
10983 >>> simplify(x_fp)
10984 1*(2**32)
10985 """
10986 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10987 _z3_assert(is_bv(v), "Second argument must be a Z3 bit-vector expression")
10988 _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
10989 ctx = _get_ctx(ctx)
10990 return FPRef(Z3_mk_fpa_to_fp_unsigned(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
10991
10992

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

10400def FPVal(sig, exp=None, fps=None, ctx=None):
10401 """Return a floating-point value of value `val` and sort `fps`.
10402 If `ctx=None`, then the global context is used.
10403
10404 >>> v = FPVal(20.0, FPSort(8, 24))
10405 >>> v
10406 1.25*(2**4)
10407 >>> print("0x%.8x" % v.exponent_as_long(False))
10408 0x00000004
10409 >>> v = FPVal(2.25, FPSort(8, 24))
10410 >>> v
10411 1.125*(2**1)
10412 >>> v = FPVal(-2.25, FPSort(8, 24))
10413 >>> v
10414 -1.125*(2**1)
10415 >>> FPVal(-0.0, FPSort(8, 24))
10416 -0.0
10417 >>> FPVal(0.0, FPSort(8, 24))
10418 +0.0
10419 >>> FPVal(+0.0, FPSort(8, 24))
10420 +0.0
10421 """
10422 ctx = _get_ctx(ctx)
10423 if is_fp_sort(exp):
10424 fps = exp
10425 exp = None
10426 elif fps is None:
10427 fps = _dflt_fps(ctx)
10428 _z3_assert(is_fp_sort(fps), "sort mismatch")
10429 if exp is None:
10430 exp = 0
10431 val = _to_float_str(sig)
10432 if val == "NaN" or val == "nan":
10433 return fpNaN(fps)
10434 elif val == "-0.0":
10435 return fpMinusZero(fps)
10436 elif val == "0.0" or val == "+0.0":
10437 return fpPlusZero(fps)
10438 elif val == "+oo" or val == "+inf" or val == "+Inf":
10439 return fpPlusInfinity(fps)
10440 elif val == "-oo" or val == "-inf" or val == "-Inf":
10441 return fpMinusInfinity(fps)
10442 else:
10443 return FPNumRef(Z3_mk_numeral(ctx.ref(), val, fps.ast), ctx)
10444
10445

◆ fpZero()

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

Definition at line 10393 of file z3py.py.

10393def fpZero(s, negative):
10394 """Create a Z3 floating-point +0.0 or -0.0 term."""
10395 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10396 _z3_assert(isinstance(negative, bool), "expected Boolean flag")
10397 return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, negative), s.ctx)
10398
10399

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

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

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

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

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

11370def Full(s):
11371 """Create the regular expression that accepts the universal language
11372 >>> e = Full(ReSort(SeqSort(IntSort())))
11373 >>> print(e)
11374 Full(ReSort(Seq(Int)))
11375 >>> e1 = Full(ReSort(StringSort()))
11376 >>> print(e1)
11377 Full(ReSort(String))
11378 """
11379 if isinstance(s, ReSortRef):
11380 return ReRef(Z3_mk_re_full(s.ctx_ref(), s.ast), s.ctx)
11381 raise Z3Exception("Non-sequence, non-regular expression sort passed to Full")
11382
11383
11384
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 5101 of file z3py.py.

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

6948def get_as_array_func(n):
6949 """Return the function declaration f associated with a Z3 expression of the form (_ as-array f)."""
6950 if z3_debug():
6951 _z3_assert(is_as_array(n), "as-array Z3 expression expected.")
6952 return FuncDeclRef(Z3_get_as_array_func_decl(n.ctx.ref(), n.as_ast()), n.ctx)
6953
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 9687 of file z3py.py.

9687def get_default_fp_sort(ctx=None):
9688 return FPSort(_dflt_fpsort_ebits, _dflt_fpsort_sbits, ctx)
9689
9690

◆ get_default_rounding_mode()

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

Definition at line 9654 of file z3py.py.

9654def get_default_rounding_mode(ctx=None):
9655 """Retrieves the global default rounding mode."""
9656 global _dflt_rounding_mode
9657 if _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO:
9658 return RTZ(ctx)
9659 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE:
9660 return RTN(ctx)
9661 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE:
9662 return RTP(ctx)
9663 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN:
9664 return RNE(ctx)
9665 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY:
9666 return RNA(ctx)
9667
9668

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

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

9160def help_simplify():
9161 """Return a string describing all options available for Z3 `simplify` procedure."""
9162 print(Z3_simplify_get_help(main_ctx().ref()))
9163
9164
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 11454 of file z3py.py.

11454def IndexOf(s, substr, offset=None):
11455 """Retrieve the index of substring within a string starting at a specified offset.
11456 >>> simplify(IndexOf("abcabc", "bc", 0))
11457 1
11458 >>> simplify(IndexOf("abcabc", "bc", 2))
11459 4
11460 """
11461 if offset is None:
11462 offset = IntVal(0)
11463 ctx = None
11464 if is_expr(offset):
11465 ctx = offset.ctx
11466 ctx = _get_ctx2(s, substr, ctx)
11467 s = _coerce_seq(s, ctx)
11468 substr = _coerce_seq(substr, ctx)
11469 if _is_int(offset):
11470 offset = IntVal(offset, ctx)
11471 return ArithRef(Z3_mk_seq_index(s.ctx_ref(), s.as_ast(), substr.as_ast(), offset.as_ast()), s.ctx)
11472
11473
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 11593 of file z3py.py.

11593def InRe(s, re):
11594 """Create regular expression membership test
11595 >>> re = Union(Re("a"),Re("b"))
11596 >>> print (simplify(InRe("a", re)))
11597 True
11598 >>> print (simplify(InRe("b", re)))
11599 True
11600 >>> print (simplify(InRe("c", re)))
11601 False
11602 """
11603 s = _coerce_seq(s, re.ctx)
11604 return BoolRef(Z3_mk_seq_in_re(s.ctx_ref(), s.as_ast(), re.as_ast()), s.ctx)
11605
11606
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 3395 of file z3py.py.

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

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

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

11627def Intersect(*args):
11628 """Create intersection of regular expressions.
11629 >>> re = Intersect(Re("a"), Re("b"), Re("c"))
11630 """
11631 args = _get_args(args)
11632 sz = len(args)
11633 if z3_debug():
11634 _z3_assert(sz > 0, "At least one argument expected.")
11635 _z3_assert(all([is_re(a) for a in args]), "All arguments must be regular expressions.")
11636 if sz == 1:
11637 return args[0]
11638 ctx = args[0].ctx
11639 v = (Ast * sz)()
11640 for i in range(sz):
11641 v[i] = args[i].as_ast()
11642 return ReRef(Z3_mk_re_intersect(ctx.ref(), sz, v), ctx)
11643
11644
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 3408 of file z3py.py.

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

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

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

11535def IntToStr(s):
11536 """Convert integer expression to string"""
11537 if not is_expr(s):
11538 s = _py2expr(s)
11539 return SeqRef(Z3_mk_int_to_str(s.ctx_ref(), s.as_ast()), s.ctx)
11540
11541
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 3333 of file z3py.py.

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

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

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

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

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

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

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

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

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

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

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

Referenced by Ext(), and Map().

◆ is_array_sort()

is_array_sort (   a)

Definition at line 4784 of file z3py.py.

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

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

6943def is_as_array(n):
6944 """Return true if n is a Z3 expression of the form (_ as-array f)."""
6945 return isinstance(n, ExprRef) and Z3_is_as_array(n.ctx.ref(), n.as_ast())
6946
6947
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 4098 of file z3py.py.

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

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

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

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

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

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

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

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

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

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

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

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

8036def is_finite_domain(a):
8037 """Return `True` if `a` is a Z3 finite-domain expression.
8038
8039 >>> s = FiniteDomainSort('S', 100)
8040 >>> b = Const('b', s)
8041 >>> is_finite_domain(b)
8042 True
8043 >>> is_finite_domain(Int('x'))
8044 False
8045 """
8046 return isinstance(a, FiniteDomainRef)
8047
8048

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

8013def is_finite_domain_sort(s):
8014 """Return True if `s` is a Z3 finite-domain sort.
8015
8016 >>> is_finite_domain_sort(FiniteDomainSort('S', 100))
8017 True
8018 >>> is_finite_domain_sort(IntSort())
8019 False
8020 """
8021 return isinstance(s, FiniteDomainSortRef)
8022
8023

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

8090def is_finite_domain_value(a):
8091 """Return `True` if `a` is a Z3 finite-domain value.
8092
8093 >>> s = FiniteDomainSort('S', 100)
8094 >>> b = Const('b', s)
8095 >>> is_finite_domain_value(b)
8096 False
8097 >>> b = FiniteDomainVal(10, s)
8098 >>> b
8099 10
8100 >>> is_finite_domain_value(b)
8101 True
8102 """
8103 return is_finite_domain(a) and _is_numeral(a.ctx, a.as_ast())
8104
8105

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

10246def is_fp(a):
10247 """Return `True` if `a` is a Z3 floating-point expression.
10248
10249 >>> b = FP('b', FPSort(8, 24))
10250 >>> is_fp(b)
10251 True
10252 >>> is_fp(b + 1.0)
10253 True
10254 >>> is_fp(Int('x'))
10255 False
10256 """
10257 return isinstance(a, FPRef)
10258
10259

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

9820def is_fp_sort(s):
9821 """Return True if `s` is a Z3 floating-point sort.
9822
9823 >>> is_fp_sort(FPSort(8, 24))
9824 True
9825 >>> is_fp_sort(IntSort())
9826 False
9827 """
9828 return isinstance(s, FPSortRef)
9829
9830

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

10260def is_fp_value(a):
10261 """Return `True` if `a` is a Z3 floating-point numeral value.
10262
10263 >>> b = FP('b', FPSort(8, 24))
10264 >>> is_fp_value(b)
10265 False
10266 >>> b = FPVal(1.0, FPSort(8, 24))
10267 >>> b
10268 1
10269 >>> is_fp_value(b)
10270 True
10271 """
10272 return is_fp(a) and _is_numeral(a.ctx, a.ast)
10273
10274

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

10080def is_fprm(a):
10081 """Return `True` if `a` is a Z3 floating-point rounding mode expression.
10082
10083 >>> rm = RNE()
10084 >>> is_fprm(rm)
10085 True
10086 >>> rm = 1.0
10087 >>> is_fprm(rm)
10088 False
10089 """
10090 return isinstance(a, FPRMRef)
10091
10092

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

9831def is_fprm_sort(s):
9832 """Return True if `s` is a Z3 floating-point rounding mode sort.
9833
9834 >>> is_fprm_sort(FPSort(8, 24))
9835 False
9836 >>> is_fprm_sort(RNE().sort())
9837 True
9838 """
9839 return isinstance(s, FPRMSortRef)
9840
9841# FP Expressions
9842
9843

◆ is_fprm_value()

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

Definition at line 10093 of file z3py.py.

10093def is_fprm_value(a):
10094 """Return `True` if `a` is a Z3 floating-point rounding mode numeral value."""
10095 return is_fprm(a) and _is_numeral(a.ctx, a.ast)
10096
10097# FP Numerals
10098
10099

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

9001def is_probe(p):
9002 """Return `True` if `p` is a Z3 probe.
9003
9004 >>> is_probe(Int('x'))
9005 False
9006 >>> is_probe(Probe('memory'))
9007 True
9008 """
9009 return isinstance(p, Probe)
9010
9011

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

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

◆ is_re()

is_re (   s)

Definition at line 11589 of file z3py.py.

11589def is_re(s):
11590 return isinstance(s, ReRef)
11591
11592

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

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

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

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

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

11271def is_seq(a):
11272 """Return `True` if `a` is a Z3 sequence expression.
11273 >>> print (is_seq(Unit(IntVal(0))))
11274 True
11275 >>> print (is_seq(StringVal("abc")))
11276 True
11277 """
11278 return isinstance(a, SeqRef)
11279
11280

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

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

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

11281def is_string(a: Any) -> bool:
11282 """Return `True` if `a` is a Z3 string expression.
11283 >>> print (is_string(StringVal("ab")))
11284 True
11285 """
11286 return isinstance(a, SeqRef) and a.is_string()
11287
11288

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

11289def is_string_value(a: Any) -> bool:
11290 """return 'True' if 'a' is a Z3 string constant expression.
11291 >>> print (is_string_value(StringVal("a")))
11292 True
11293 >>> print (is_string_value(StringVal("a") + StringVal("b")))
11294 False
11295 """
11296 return isinstance(a, SeqRef) and a.is_string_value()
11297

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

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

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

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

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

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

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

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

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

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

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

11474def LastIndexOf(s, substr):
11475 """Retrieve the last index of substring within a string"""
11476 ctx = None
11477 ctx = _get_ctx2(s, substr, ctx)
11478 s = _coerce_seq(s, ctx)
11479 substr = _coerce_seq(substr, ctx)
11480 return ArithRef(Z3_mk_seq_last_index(s.ctx_ref(), s.as_ast(), substr.as_ast()), s.ctx)
11481
11482
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 11483 of file z3py.py.

11483def Length(s):
11484 """Obtain the length of a sequence 's'
11485 >>> l = Length(StringVal("abc"))
11486 >>> simplify(l)
11487 3
11488 """
11489 s = _coerce_seq(s)
11490 return ArithRef(Z3_mk_seq_length(s.ctx_ref(), s.as_ast()), s.ctx)
11491
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 11745 of file z3py.py.

11745def LinearOrder(a, index):
11746 return FuncDeclRef(Z3_mk_linear_order(a.ctx_ref(), a.ast, index), a.ctx)
11747
11748
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 11695 of file z3py.py.

11695def Loop(re, lo, hi=0):
11696 """Create the regular expression accepting between a lower and upper bound repetitions
11697 >>> re = Loop(Re("a"), 1, 3)
11698 >>> print(simplify(InRe("aa", re)))
11699 True
11700 >>> print(simplify(InRe("aaaa", re)))
11701 False
11702 >>> print(simplify(InRe("", re)))
11703 False
11704 """
11705 if z3_debug():
11706 _z3_assert(is_expr(re), "expression expected")
11707 return ReRef(Z3_mk_re_loop(re.ctx_ref(), re.as_ast(), lo, hi), re.ctx)
11708
11709
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 4476 of file z3py.py.

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

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

6935def Model(ctx=None, eval = {}):
6936 ctx = _get_ctx(ctx)
6937 mdl = ModelRef(Z3_mk_model(ctx.ref()), ctx)
6938 for k, v in eval.items():
6939 mdl.update_value(k, v)
6940 return mdl
6941
6942
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 11785 of file z3py.py.

11785def on_clause_eh(ctx, p, n, dep, clause):
11786 onc = _my_hacky_class
11787 p = _to_expr_ref(to_Ast(p), onc.ctx)
11788 clause = AstVector(to_AstVectorObj(clause), onc.ctx)
11789 deps = [dep[i] for i in range(n)]
11790 onc.on_clause(p, deps, clause)
11791

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

11660def Option(re):
11661 """Create the regular expression that optionally accepts the argument.
11662 >>> re = Option(Re("a"))
11663 >>> print(simplify(InRe("a", re)))
11664 True
11665 >>> print(simplify(InRe("", re)))
11666 True
11667 >>> print(simplify(InRe("aa", re)))
11668 False
11669 """
11670 if z3_debug():
11671 _z3_assert(is_expr(re), "expression expected")
11672 return ReRef(Z3_mk_re_option(re.ctx_ref(), re.as_ast()), re.ctx)
11673
11674
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 8694 of file z3py.py.

8694def OrElse(*ts, **ks):
8695 """Return a tactic that applies the tactics in `*ts` until one of them succeeds (it doesn't fail).
8696
8697 >>> x = Int('x')
8698 >>> t = OrElse(Tactic('split-clause'), Tactic('skip'))
8699 >>> # Tactic split-clause fails if there is no clause in the given goal.
8700 >>> t(x == 0)
8701 [[x == 0]]
8702 >>> t(Or(x == 0, x == 1))
8703 [[x == 0], [x == 1]]
8704 """
8705 if z3_debug():
8706 _z3_assert(len(ts) >= 2, "At least two arguments expected")
8707 ctx = ks.get("ctx", None)
8708 num = len(ts)
8709 r = ts[0]
8710 for i in range(num - 1):
8711 r = _or_else(r, ts[i + 1], ctx)
8712 return r
8713
8714

◆ ParAndThen()

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

Definition at line 8750 of file z3py.py.

8750def ParAndThen(t1, t2, ctx=None):
8751 """Alias for ParThen(t1, t2, ctx)."""
8752 return ParThen(t1, t2, ctx)
8753
8754

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

8715def ParOr(*ts, **ks):
8716 """Return a tactic that applies the tactics in `*ts` in parallel until one of them succeeds (it doesn't fail).
8717
8718 >>> x = Int('x')
8719 >>> t = ParOr(Tactic('simplify'), Tactic('fail'))
8720 >>> t(x + 1 == 2)
8721 [[x == 1]]
8722 """
8723 if z3_debug():
8724 _z3_assert(len(ts) >= 2, "At least two arguments expected")
8725 ctx = _get_ctx(ks.get("ctx", None))
8726 ts = [_to_tactic(t, ctx) for t in ts]
8727 sz = len(ts)
8728 _args = (TacticObj * sz)()
8729 for i in range(sz):
8730 _args[i] = ts[i].tactic
8731 return Tactic(Z3_tactic_par_or(ctx.ref(), sz, _args), ctx)
8732
8733
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 9630 of file z3py.py.

9630def parse_smt2_file(f, sorts={}, decls={}, ctx=None):
9631 """Parse a file in SMT 2.0 format using the given sorts and decls.
9632
9633 This function is similar to parse_smt2_string().
9634 """
9635 ctx = _get_ctx(ctx)
9636 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
9637 dsz, dnames, ddecls = _dict2darray(decls, ctx)
9638 return AstVector(Z3_parse_smtlib2_file(ctx.ref(), f, ssz, snames, ssorts, dsz, dnames, ddecls), ctx)
9639
9640
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 9609 of file z3py.py.

9609def parse_smt2_string(s, sorts={}, decls={}, ctx=None):
9610 """Parse a string in SMT 2.0 format using the given sorts and decls.
9611
9612 The arguments sorts and decls are Python dictionaries used to initialize
9613 the symbol table used for the SMT 2.0 parser.
9614
9615 >>> parse_smt2_string('(declare-const x Int) (assert (> x 0)) (assert (< x 10))')
9616 [x > 0, x < 10]
9617 >>> x, y = Ints('x y')
9618 >>> f = Function('f', IntSort(), IntSort())
9619 >>> parse_smt2_string('(assert (> (+ foo (g bar)) 0))', decls={ 'foo' : x, 'bar' : y, 'g' : f})
9620 [x + f(y) > 0]
9621 >>> parse_smt2_string('(declare-const a U) (assert (> a 0))', sorts={ 'U' : IntSort() })
9622 [a > 0]
9623 """
9624 ctx = _get_ctx(ctx)
9625 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
9626 dsz, dnames, ddecls = _dict2darray(decls, ctx)
9627 return AstVector(Z3_parse_smtlib2_string(ctx.ref(), s, ssz, snames, ssorts, dsz, dnames, ddecls), ctx)
9628
9629
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 8734 of file z3py.py.

8734def ParThen(t1, t2, ctx=None):
8735 """Return a tactic that applies t1 and then t2 to every subgoal produced by t1.
8736 The subgoals are processed in parallel.
8737
8738 >>> x, y = Ints('x y')
8739 >>> t = ParThen(Tactic('split-clause'), Tactic('propagate-values'))
8740 >>> t(And(Or(x == 1, x == 2), y == x + 1))
8741 [[x == 1, y == 2], [x == 2, y == 3]]
8742 """
8743 t1 = _to_tactic(t1, ctx)
8744 t2 = _to_tactic(t2, ctx)
8745 if z3_debug():
8746 _z3_assert(t1.ctx == t2.ctx, "Context mismatch")
8747 return Tactic(Z3_tactic_par_and_then(t1.ctx.ref(), t1.tactic, t2.tactic), t1.ctx)
8748
8749
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 11741 of file z3py.py.

11741def PartialOrder(a, index):
11742 return FuncDeclRef(Z3_mk_partial_order(a.ctx_ref(), a.ast, index), a.ctx)
11743
11744
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 9386 of file z3py.py.

9386def PbEq(args, k, ctx=None):
9387 """Create a Pseudo-Boolean equality k constraint.
9388
9389 >>> a, b, c = Bools('a b c')
9390 >>> f = PbEq(((a,1),(b,3),(c,2)), 3)
9391 """
9392 _z3_check_cint_overflow(k, "k")
9393 ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
9394 return BoolRef(Z3_mk_pbeq(ctx.ref(), sz, _args, _coeffs, k), ctx)
9395
9396
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 9375 of file z3py.py.

9375def PbGe(args, k):
9376 """Create a Pseudo-Boolean inequality k constraint.
9377
9378 >>> a, b, c = Bools('a b c')
9379 >>> f = PbGe(((a,1),(b,3),(c,2)), 3)
9380 """
9381 _z3_check_cint_overflow(k, "k")
9382 ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
9383 return BoolRef(Z3_mk_pbge(ctx.ref(), sz, _args, _coeffs, k), ctx)
9384
9385
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 9364 of file z3py.py.

9364def PbLe(args, k):
9365 """Create a Pseudo-Boolean inequality k constraint.
9366
9367 >>> a, b, c = Bools('a b c')
9368 >>> f = PbLe(((a,1),(b,3),(c,2)), 3)
9369 """
9370 _z3_check_cint_overflow(k, "k")
9371 ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
9372 return BoolRef(Z3_mk_pble(ctx.ref(), sz, _args, _coeffs, k), ctx)
9373
9374
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 11753 of file z3py.py.

11753def PiecewiseLinearOrder(a, index):
11754 return FuncDeclRef(Z3_mk_piecewise_linear_order(a.ctx_ref(), a.ast, index), a.ctx)
11755
11756
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 11645 of file z3py.py.

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

11390def PrefixOf(a, b):
11391 """Check if 'a' is a prefix of 'b'
11392 >>> s1 = PrefixOf("ab", "abc")
11393 >>> simplify(s1)
11394 True
11395 >>> s2 = PrefixOf("bc", "abc")
11396 >>> simplify(s2)
11397 False
11398 """
11399 ctx = _get_ctx2(a, b)
11400 a = _coerce_seq(a, ctx)
11401 b = _coerce_seq(b, ctx)
11402 return BoolRef(Z3_mk_seq_prefix(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
11403
11404
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 9030 of file z3py.py.

9030def probe_description(name, ctx=None):
9031 """Return a short description for the probe named `name`.
9032
9033 >>> d = probe_description('memory')
9034 """
9035 ctx = _get_ctx(ctx)
9036 return Z3_probe_get_descr(ctx.ref(), name)
9037
9038
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 9019 of file z3py.py.

9019def probes(ctx=None):
9020 """Return a list of all available probes in Z3.
9021
9022 >>> l = probes()
9023 >>> l.count('memory') == 1
9024 True
9025 """
9026 ctx = _get_ctx(ctx)
9027 return [Z3_get_probe_name(ctx.ref(), i) for i in range(Z3_get_num_probes(ctx.ref()))]
9028
9029
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 9271 of file z3py.py.

9271def Product(*args):
9272 """Create the product of the Z3 expressions.
9273
9274 >>> a, b, c = Ints('a b c')
9275 >>> Product(a, b, c)
9276 a*b*c
9277 >>> Product([a, b, c])
9278 a*b*c
9279 >>> A = IntVector('a', 5)
9280 >>> Product(A)
9281 a__0*a__1*a__2*a__3*a__4
9282 """
9283 args = _get_args(args)
9284 if len(args) == 0:
9285 return 1
9286 ctx = _ctx_from_ast_arg_list(args)
9287 if ctx is None:
9288 return _reduce(lambda a, b: a * b, args, 1)
9289 args = _coerce_expr_list(args, ctx)
9290 if is_bv(args[0]):
9291 return _reduce(lambda a, b: a * b, args, 1)
9292 else:
9293 _args, sz = _to_ast_array(args)
9294 return ArithRef(Z3_mk_mul(ctx.ref(), sz, _args), ctx)
9295
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 11950 of file z3py.py.

11950def PropagateFunction(name, *sig):
11951 """Create a function that gets tracked by user propagator.
11952 Every term headed by this function symbol is tracked.
11953 If a term is fixed and the fixed callback is registered a
11954 callback is invoked that the term headed by this function is fixed.
11955 """
11956 sig = _get_args(sig)
11957 if z3_debug():
11958 _z3_assert(len(sig) > 0, "At least two arguments expected")
11959 arity = len(sig) - 1
11960 rng = sig[arity]
11961 if z3_debug():
11962 _z3_assert(is_sort(rng), "Z3 sort expected")
11963 dom = (Sort * arity)()
11964 for i in range(arity):
11965 if z3_debug():
11966 _z3_assert(is_sort(sig[i]), "Z3 sort expected")
11967 dom[i] = sig[i].ast
11968 ctx = rng.ctx
11969 return FuncDeclRef(Z3_solver_propagate_declare(ctx.ref(), to_symbol(name, ctx), arity, dom, rng.ast), ctx)
11970
11971
11972
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 9458 of file z3py.py.

9458def prove(claim, show=False, **keywords):
9459 """Try to prove the given claim.
9460
9461 This is a simple function for creating demonstrations. It tries to prove
9462 `claim` by showing the negation is unsatisfiable.
9463
9464 >>> p, q = Bools('p q')
9465 >>> prove(Not(And(p, q)) == Or(Not(p), Not(q)))
9466 proved
9467 """
9468 if z3_debug():
9469 _z3_assert(is_bool(claim), "Z3 Boolean expression expected")
9470 s = Solver()
9471 s.set(**keywords)
9472 s.add(Not(claim))
9473 if show:
9474 print(s)
9475 r = s.check()
9476 if r == unsat:
9477 print("proved")
9478 elif r == unknown:
9479 print("failed to prove")
9480 print(s.model())
9481 else:
9482 print("counterexample")
9483 print(s.model())
9484
9485

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

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

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

11710def Range(lo, hi, ctx=None):
11711 """Create the range regular expression over two sequences of length 1
11712 >>> range = Range("a","z")
11713 >>> print(simplify(InRe("b", range)))
11714 True
11715 >>> print(simplify(InRe("bb", range)))
11716 False
11717 """
11718 lo = _coerce_seq(lo, ctx)
11719 hi = _coerce_seq(hi, ctx)
11720 if z3_debug():
11721 _z3_assert(is_expr(lo), "expression expected")
11722 _z3_assert(is_expr(hi), "expression expected")
11723 return ReRef(Z3_mk_re_range(lo.ctx_ref(), lo.ast, hi.ast), lo.ctx)
11724
Z3_ast Z3_API Z3_mk_re_range(Z3_context c, Z3_ast lo, Z3_ast hi)
Create the range regular expression over two sequences of length 1.

◆ RatVal()

RatVal (   a,
  b,
  ctx = None 
)
Return a Z3 rational a/b.

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

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

Definition at line 3364 of file z3py.py.

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

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

11554def Re(s, ctx=None):
11555 """The regular expression that accepts sequence 's'
11556 >>> s1 = Re("ab")
11557 >>> s2 = Re(StringVal("ab"))
11558 >>> s3 = Re(Unit(BoolVal(True)))
11559 """
11560 s = _coerce_seq(s, ctx)
11561 return ReRef(Z3_mk_seq_to_re(s.ctx_ref(), s.as_ast()), s.ctx)
11562
11563
11564# Regular expressions
11565
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 3448 of file z3py.py.

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

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

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

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

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

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

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

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

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

8783def Repeat(t, max=4294967295, ctx=None):
8784 """Return a tactic that keeps applying `t` until the goal is not modified anymore
8785 or the maximum number of iterations `max` is reached.
8786
8787 >>> x, y = Ints('x y')
8788 >>> c = And(Or(x == 0, x == 1), Or(y == 0, y == 1), x > y)
8789 >>> t = Repeat(OrElse(Tactic('split-clause'), Tactic('skip')))
8790 >>> r = t(c)
8791 >>> for subgoal in r: print(subgoal)
8792 [x == 0, y == 0, x > y]
8793 [x == 0, y == 1, x > y]
8794 [x == 1, y == 0, x > y]
8795 [x == 1, y == 1, x > y]
8796 >>> t = Then(t, Tactic('propagate-values'))
8797 >>> t(c)
8798 [[x == 1, y == 0]]
8799 """
8800 t = _to_tactic(t, ctx)
8801 return Tactic(Z3_tactic_repeat(t.ctx.ref(), t.tactic, max), t.ctx)
8802
8803
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 4598 of file z3py.py.

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

11439def Replace(s, src, dst):
11440 """Replace the first occurrence of 'src' by 'dst' in 's'
11441 >>> r = Replace("aaa", "a", "b")
11442 >>> simplify(r)
11443 "baa"
11444 """
11445 ctx = _get_ctx2(dst, s)
11446 if ctx is None and is_expr(src):
11447 ctx = src.ctx
11448 src = _coerce_seq(src, ctx)
11449 dst = _coerce_seq(dst, ctx)
11450 s = _coerce_seq(s, ctx)
11451 return SeqRef(Z3_mk_seq_replace(src.ctx_ref(), s.as_ast(), src.as_ast(), dst.as_ast()), s.ctx)
11452
11453
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 11573 of file z3py.py.

11573def ReSort(s):
11574 if is_ast(s):
11575 return ReSortRef(Z3_mk_re_sort(s.ctx.ref(), s.ast), s.ctx)
11576 if s is None or isinstance(s, Context):
11577 ctx = _get_ctx(s)
11578 return ReSortRef(Z3_mk_re_sort(ctx.ref(), Z3_mk_string_sort(ctx.ref())), s.ctx)
11579 raise Z3Exception("Regular expression sort constructor expects either a string or a context or no argument")
11580
11581
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 10045 of file z3py.py.

10045def RNA(ctx=None):
10046 ctx = _get_ctx(ctx)
10047 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_away(ctx.ref()), ctx)
10048
10049
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 10035 of file z3py.py.

10035def RNE(ctx=None):
10036 ctx = _get_ctx(ctx)
10037 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_even(ctx.ref()), ctx)
10038
10039
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 4508 of file z3py.py.

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

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

10040def RoundNearestTiesToAway(ctx=None):
10041 ctx = _get_ctx(ctx)
10042 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_away(ctx.ref()), ctx)
10043
10044

◆ RoundNearestTiesToEven()

RoundNearestTiesToEven (   ctx = None)

Definition at line 10030 of file z3py.py.

10030def RoundNearestTiesToEven(ctx=None):
10031 ctx = _get_ctx(ctx)
10032 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_even(ctx.ref()), ctx)
10033
10034

◆ RoundTowardNegative()

RoundTowardNegative (   ctx = None)

Definition at line 10060 of file z3py.py.

10060def RoundTowardNegative(ctx=None):
10061 ctx = _get_ctx(ctx)
10062 return FPRMRef(Z3_mk_fpa_round_toward_negative(ctx.ref()), ctx)
10063
10064
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 10050 of file z3py.py.

10050def RoundTowardPositive(ctx=None):
10051 ctx = _get_ctx(ctx)
10052 return FPRMRef(Z3_mk_fpa_round_toward_positive(ctx.ref()), ctx)
10053
10054
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 10070 of file z3py.py.

10070def RoundTowardZero(ctx=None):
10071 ctx = _get_ctx(ctx)
10072 return FPRMRef(Z3_mk_fpa_round_toward_zero(ctx.ref()), ctx)
10073
10074
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 10065 of file z3py.py.

10065def RTN(ctx=None):
10066 ctx = _get_ctx(ctx)
10067 return FPRMRef(Z3_mk_fpa_round_toward_negative(ctx.ref()), ctx)
10068
10069

◆ RTP()

RTP (   ctx = None)

Definition at line 10055 of file z3py.py.

10055def RTP(ctx=None):
10056 ctx = _get_ctx(ctx)
10057 return FPRMRef(Z3_mk_fpa_round_toward_positive(ctx.ref()), ctx)
10058
10059

◆ RTZ()

RTZ (   ctx = None)

Definition at line 10075 of file z3py.py.

10075def RTZ(ctx=None):
10076 ctx = _get_ctx(ctx)
10077 return FPRMRef(Z3_mk_fpa_round_toward_zero(ctx.ref()), ctx)
10078
10079

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

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

◆ SeqFoldLeft()

SeqFoldLeft (   f,
  a,
  s 
)

Definition at line 11506 of file z3py.py.

11506def SeqFoldLeft(f, a, s):
11507 ctx = _get_ctx2(f, s)
11508 s = _coerce_seq(s, ctx)
11509 a = _py2expr(a)
11510 return _to_expr_ref(Z3_mk_seq_foldl(s.ctx_ref(), f.as_ast(), a.as_ast(), s.as_ast()), ctx)
11511
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 11512 of file z3py.py.

11512def SeqFoldLeftI(f, i, a, s):
11513 ctx = _get_ctx2(f, s)
11514 s = _coerce_seq(s, ctx)
11515 a = _py2expr(a)
11516 i = _py2expr(i)
11517 return _to_expr_ref(Z3_mk_seq_foldli(s.ctx_ref(), f.as_ast(), i.as_ast(), a.as_ast(), s.as_ast()), ctx)
11518
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 11492 of file z3py.py.

11492def SeqMap(f, s):
11493 """Map function 'f' over sequence 's'"""
11494 ctx = _get_ctx2(f, s)
11495 s = _coerce_seq(s, ctx)
11496 return _to_expr_ref(Z3_mk_seq_map(s.ctx_ref(), f.as_ast(), s.as_ast()), ctx)
11497
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 11498 of file z3py.py.

11498def SeqMapI(f, i, s):
11499 """Map function 'f' over sequence 's' at index 'i'"""
11500 ctx = _get_ctx2(f, s)
11501 s = _coerce_seq(s, ctx)
11502 if not is_expr(i):
11503 i = _py2expr(i)
11504 return _to_expr_ref(Z3_mk_seq_mapi(s.ctx_ref(), f.as_ast(), i.as_ast(), s.as_ast()), ctx)
11505
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 11139 of file z3py.py.

11139def SeqSort(s):
11140 """Create a sequence sort over elements provided in the argument
11141 >>> s = SeqSort(IntSort())
11142 >>> s == Unit(IntVal(1)).sort()
11143 True
11144 """
11145 return SeqSortRef(Z3_mk_seq_sort(s.ctx_ref(), s.ast), s.ctx)
11146
11147
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 9691 of file z3py.py.

9691def set_default_fp_sort(ebits, sbits, ctx=None):
9692 global _dflt_fpsort_ebits
9693 global _dflt_fpsort_sbits
9694 _dflt_fpsort_ebits = ebits
9695 _dflt_fpsort_sbits = sbits
9696
9697

◆ set_default_rounding_mode()

set_default_rounding_mode (   rm,
  ctx = None 
)

Definition at line 9678 of file z3py.py.

9678def set_default_rounding_mode(rm, ctx=None):
9679 global _dflt_rounding_mode
9680 if is_fprm_value(rm):
9681 _dflt_rounding_mode = rm.kind()
9682 else:
9683 _z3_assert(_dflt_rounding_mode in _ROUNDING_MODES, "illegal rounding mode")
9684 _dflt_rounding_mode = rm
9685
9686

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

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

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

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

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

5123def SetIntersect(*args):
5124 """ Take the union of sets
5125 >>> a = Const('a', SetSort(IntSort()))
5126 >>> b = Const('b', SetSort(IntSort()))
5127 >>> SetIntersect(a, b)
5128 intersection(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_intersect(ctx.ref(), sz, _args), ctx)
5134
5135
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 5087 of file z3py.py.

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

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

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

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

7708def SimpleSolver(ctx=None, logFile=None):
7709 """Return a simple general purpose solver with limited amount of preprocessing.
7710
7711 >>> s = SimpleSolver()
7712 >>> x = Int('x')
7713 >>> s.add(x > 0)
7714 >>> s.check()
7715 sat
7716 """
7717 ctx = _get_ctx(ctx)
7718 return Solver(Z3_mk_simple_solver(ctx.ref()), ctx, logFile)
7719
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 9135 of file z3py.py.

9135def simplify(a, *arguments, **keywords):
9136 """Simplify the expression `a` using the given options.
9137
9138 This function has many options. Use `help_simplify` to obtain the complete list.
9139
9140 >>> x = Int('x')
9141 >>> y = Int('y')
9142 >>> simplify(x + 1 + y + x + 1)
9143 2 + 2*x + y
9144 >>> simplify((x + 1)*(y + 1), som=True)
9145 1 + x + y + x*y
9146 >>> simplify(Distinct(x, y, 1), blast_distinct=True)
9147 And(Not(x == y), Not(x == 1), Not(y == 1))
9148 >>> simplify(And(x == 0, y == 1), elim_and=True)
9149 Not(Or(Not(x == 0), Not(y == 1)))
9150 """
9151 if z3_debug():
9152 _z3_assert(is_expr(a), "Z3 expression expected")
9153 if len(arguments) > 0 or len(keywords) > 0:
9154 p = args2params(arguments, keywords, a.ctx)
9155 return _to_expr_ref(Z3_simplify_ex(a.ctx_ref(), a.as_ast(), p.params), a.ctx)
9156 else:
9157 return _to_expr_ref(Z3_simplify(a.ctx_ref(), a.as_ast()), a.ctx)
9158
9159
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 9165 of file z3py.py.

9165def simplify_param_descrs():
9166 """Return the set of parameter descriptions for Z3 `simplify` procedure."""
9167 return ParamDescrsRef(Z3_simplify_get_param_descrs(main_ctx().ref()), main_ctx())
9168
9169
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 9397 of file z3py.py.

9397def solve(*args, **keywords):
9398 """Solve the constraints `*args`.
9399
9400 This is a simple function for creating demonstrations. It creates a solver,
9401 configure it using the options in `keywords`, adds the constraints
9402 in `args`, and invokes check.
9403
9404 >>> a = Int('a')
9405 >>> solve(a > 0, a < 2)
9406 [a = 1]
9407 """
9408 show = keywords.pop("show", False)
9409 s = Solver()
9410 s.set(**keywords)
9411 s.add(*args)
9412 if show:
9413 print(s)
9414 r = s.check()
9415 if r == unsat:
9416 print("no solution")
9417 elif r == unknown:
9418 print("failed to solve")
9419 try:
9420 print(s.model())
9421 except Z3Exception:
9422 return
9423 else:
9424 print(s.model())
9425
9426

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

9427def solve_using(s, *args, **keywords):
9428 """Solve the constraints `*args` using solver `s`.
9429
9430 This is a simple function for creating demonstrations. It is similar to `solve`,
9431 but it uses the given solver `s`.
9432 It configures solver `s` using the options in `keywords`, adds the constraints
9433 in `args`, and invokes check.
9434 """
9435 show = keywords.pop("show", False)
9436 if z3_debug():
9437 _z3_assert(isinstance(s, Solver), "Solver object expected")
9438 s.set(**keywords)
9439 s.add(*args)
9440 if show:
9441 print("Problem:")
9442 print(s)
9443 r = s.check()
9444 if r == unsat:
9445 print("no solution")
9446 elif r == unknown:
9447 print("failed to solve")
9448 try:
9449 print(s.model())
9450 except Z3Exception:
9451 return
9452 else:
9453 if show:
9454 print("Solution:")
9455 print(s.model())
9456
9457

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

7687def SolverFor(logic, ctx=None, logFile=None):
7688 """Create a solver customized for the given logic.
7689
7690 The parameter `logic` is a string. It should be contains
7691 the name of a SMT-LIB logic.
7692 See http://www.smtlib.org/ for the name of all available logics.
7693
7694 >>> s = SolverFor("QF_LIA")
7695 >>> x = Int('x')
7696 >>> s.add(x > 0)
7697 >>> s.add(x < 2)
7698 >>> s.check()
7699 sat
7700 >>> s.model()
7701 [x = 1]
7702 """
7703 ctx = _get_ctx(ctx)
7704 logic = to_symbol(logic)
7705 return Solver(Z3_mk_solver_for_logic(ctx.ref(), logic), ctx, logFile)
7706
7707
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 3560 of file z3py.py.

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

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

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

11680def Star(re):
11681 """Create the regular expression accepting zero or more repetitions of argument.
11682 >>> re = Star(Re("a"))
11683 >>> print(simplify(InRe("aa", re)))
11684 True
11685 >>> print(simplify(InRe("ab", re)))
11686 False
11687 >>> print(simplify(InRe("", re)))
11688 True
11689 """
11690 if z3_debug():
11691 _z3_assert(is_expr(re), "expression expected")
11692 return ReRef(Z3_mk_re_star(re.ctx_ref(), re.as_ast()), re.ctx)
11693
11694
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 4967 of file z3py.py.

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

Referenced by ModelRef.get_interp().

◆ StrFromCode()

StrFromCode (   c)
Convert code to a string

Definition at line 11548 of file z3py.py.

11548def StrFromCode(c):
11549 """Convert code to a string"""
11550 if not is_expr(c):
11551 c = _py2expr(c)
11552 return SeqRef(Z3_mk_string_from_code(c.ctx_ref(), c.as_ast()), c.ctx)
11553
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 11305 of file z3py.py.

11305def String(name, ctx=None):
11306 """Return a string constant named `name`. If `ctx=None`, then the global context is used.
11307
11308 >>> x = String('x')
11309 """
11310 ctx = _get_ctx(ctx)
11311 return SeqRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), StringSort(ctx).ast), ctx)
11312
11313

◆ Strings()

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

Definition at line 11314 of file z3py.py.

11314def Strings(names, ctx=None):
11315 """Return a tuple of String constants. """
11316 ctx = _get_ctx(ctx)
11317 if isinstance(names, str):
11318 names = names.split(" ")
11319 return [String(name, ctx) for name in names]
11320
11321

◆ StringSort()

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

Definition at line 11120 of file z3py.py.

11120def StringSort(ctx=None):
11121 """Create a string sort
11122 >>> s = StringSort()
11123 >>> print(s)
11124 String
11125 """
11126 ctx = _get_ctx(ctx)
11127 return SeqSortRef(Z3_mk_string_sort(ctx.ref()), ctx)
11128

◆ StringVal()

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

Definition at line 11298 of file z3py.py.

11298def StringVal(s, ctx=None):
11299 """create a string expression"""
11300 s = "".join(str(ch) if 32 <= ord(ch) and ord(ch) < 127 else "\\u{%x}" % (ord(ch)) for ch in s)
11301 ctx = _get_ctx(ctx)
11302 return SeqRef(Z3_mk_string(ctx.ref(), s), ctx)
11303
11304
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 11542 of file z3py.py.

11542def StrToCode(s):
11543 """Convert a unit length string to integer code"""
11544 if not is_expr(s):
11545 s = _py2expr(s)
11546 return ArithRef(Z3_mk_string_to_code(s.ctx_ref(), s.as_ast()), s.ctx)
11547
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 11519 of file z3py.py.

11519def StrToInt(s):
11520 """Convert string expression to integer
11521 >>> a = StrToInt("1")
11522 >>> simplify(1 == a)
11523 True
11524 >>> b = StrToInt("2")
11525 >>> simplify(1 == b)
11526 False
11527 >>> c = StrToInt(IntToStr(2))
11528 >>> simplify(1 == c)
11529 False
11530 """
11531 s = _coerce_seq(s)
11532 return ArithRef(Z3_mk_str_to_int(s.ctx_ref(), s.as_ast()), s.ctx)
11533
11534
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 11336 of file z3py.py.

11336def SubSeq(s, offset, length):
11337 """Extract substring or subsequence starting at offset.
11338
11339 This is a convenience function that redirects to Extract(s, offset, length).
11340
11341 >>> s = StringVal("hello world")
11342 >>> SubSeq(s, 0, 5) # Extract "hello"
11343 str.substr("hello world", 0, 5)
11344 >>> simplify(SubSeq(StringVal("testing"), 2, 4))
11345 "stin"
11346 """
11347 return Extract(s, offset, length)
11348
11349

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

9170def substitute(t, *m):
9171 """Apply substitution m on t, m is a list of pairs of the form (from, to).
9172 Every occurrence in t of from is replaced with to.
9173
9174 >>> x = Int('x')
9175 >>> y = Int('y')
9176 >>> substitute(x + 1, (x, y + 1))
9177 y + 1 + 1
9178 >>> f = Function('f', IntSort(), IntSort())
9179 >>> substitute(f(x) + f(y), (f(x), IntVal(1)), (f(y), IntVal(1)))
9180 1 + 1
9181 """
9182 if isinstance(m, tuple):
9183 m1 = _get_args(m)
9184 if isinstance(m1, list) and all(isinstance(p, tuple) for p in m1):
9185 m = m1
9186 if z3_debug():
9187 _z3_assert(is_expr(t), "Z3 expression expected")
9188 _z3_assert(
9189 all([isinstance(p, tuple) and is_expr(p[0]) and is_expr(p[1]) for p in m]),
9190 "Z3 invalid substitution, expression pairs expected.")
9191 _z3_assert(
9192 all([p[0].sort().eq(p[1].sort()) for p in m]),
9193 'Z3 invalid substitution, mismatching "from" and "to" sorts.')
9194 num = len(m)
9195 _from = (Ast * num)()
9196 _to = (Ast * num)()
9197 for i in range(num):
9198 _from[i] = m[i][0].as_ast()
9199 _to[i] = m[i][1].as_ast()
9200 return _to_expr_ref(Z3_substitute(t.ctx.ref(), t.as_ast(), num, _from, _to), t.ctx)
9201
9202
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 9223 of file z3py.py.

9223def substitute_funs(t, *m):
9224 """Apply substitution m on t, m is a list of pairs of a function and expression (from, to)
9225 Every occurrence in to of the function from is replaced with the expression to.
9226 The expression to can have free variables, that refer to the arguments of from.
9227 For examples, see
9228 """
9229 if isinstance(m, tuple):
9230 m1 = _get_args(m)
9231 if isinstance(m1, list) and all(isinstance(p, tuple) for p in m1):
9232 m = m1
9233 if z3_debug():
9234 _z3_assert(is_expr(t), "Z3 expression expected")
9235 _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.")
9236 num = len(m)
9237 _from = (FuncDecl * num)()
9238 _to = (Ast * num)()
9239 for i in range(num):
9240 _from[i] = m[i][0].as_func_decl()
9241 _to[i] = m[i][1].as_ast()
9242 return _to_expr_ref(Z3_substitute_funs(t.ctx.ref(), t.as_ast(), num, _from, _to), t.ctx)
9243
9244
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 9203 of file z3py.py.

9203def substitute_vars(t, *m):
9204 """Substitute the free variables in t with the expression in m.
9205
9206 >>> v0 = Var(0, IntSort())
9207 >>> v1 = Var(1, IntSort())
9208 >>> x = Int('x')
9209 >>> f = Function('f', IntSort(), IntSort(), IntSort())
9210 >>> # replace v0 with x+1 and v1 with x
9211 >>> substitute_vars(f(v0, v1), x + 1, x)
9212 f(x + 1, x)
9213 """
9214 if z3_debug():
9215 _z3_assert(is_expr(t), "Z3 expression expected")
9216 _z3_assert(all([is_expr(n) for n in m]), "Z3 invalid substitution, list of expressions expected.")
9217 num = len(m)
9218 _to = (Ast * num)()
9219 for i in range(num):
9220 _to[i] = m[i].as_ast()
9221 return _to_expr_ref(Z3_substitute_vars(t.ctx.ref(), t.as_ast(), num, _to), t.ctx)
9222
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 11322 of file z3py.py.

11322def SubString(s, offset, length):
11323 """Extract substring or subsequence starting at offset.
11324
11325 This is a convenience function that redirects to Extract(s, offset, length).
11326
11327 >>> s = StringVal("hello world")
11328 >>> SubString(s, 6, 5) # Extract "world"
11329 str.substr("hello world", 6, 5)
11330 >>> simplify(SubString(StringVal("hello"), 1, 3))
11331 "ell"
11332 """
11333 return Extract(s, offset, length)
11334
11335

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

11405def SuffixOf(a, b):
11406 """Check if 'a' is a suffix of 'b'
11407 >>> s1 = SuffixOf("ab", "abc")
11408 >>> simplify(s1)
11409 False
11410 >>> s2 = SuffixOf("bc", "abc")
11411 >>> simplify(s2)
11412 True
11413 """
11414 ctx = _get_ctx2(a, b)
11415 a = _coerce_seq(a, ctx)
11416 b = _coerce_seq(b, ctx)
11417 return BoolRef(Z3_mk_seq_suffix(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
11418
11419
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 9245 of file z3py.py.

9245def Sum(*args):
9246 """Create the sum of the Z3 expressions.
9247
9248 >>> a, b, c = Ints('a b c')
9249 >>> Sum(a, b, c)
9250 a + b + c
9251 >>> Sum([a, b, c])
9252 a + b + c
9253 >>> A = IntVector('a', 5)
9254 >>> Sum(A)
9255 a__0 + a__1 + a__2 + a__3 + a__4
9256 """
9257 args = _get_args(args)
9258 if len(args) == 0:
9259 return 0
9260 ctx = _ctx_from_ast_arg_list(args)
9261 if ctx is None:
9262 return _reduce(lambda a, b: a + b, args, 0)
9263 args = _coerce_expr_list(args, ctx)
9264 if is_bv(args[0]):
9265 return _reduce(lambda a, b: a + b, args, 0)
9266 else:
9267 _args, sz = _to_ast_array(args)
9268 return ArithRef(Z3_mk_add(ctx.ref(), sz, _args), ctx)
9269
9270
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 8824 of file z3py.py.

8824def tactic_description(name, ctx=None):
8825 """Return a short description for the tactic named `name`.
8826
8827 >>> d = tactic_description('simplify')
8828 """
8829 ctx = _get_ctx(ctx)
8830 return Z3_tactic_get_descr(ctx.ref(), name)
8831
8832
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 8813 of file z3py.py.

8813def tactics(ctx=None):
8814 """Return a list of all available tactics in Z3.
8815
8816 >>> l = tactics()
8817 >>> l.count('simplify') == 1
8818 True
8819 """
8820 ctx = _get_ctx(ctx)
8821 return [Z3_get_tactic_name(ctx.ref(), i) for i in range(Z3_get_num_tactics(ctx.ref()))]
8822
8823
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 8681 of file z3py.py.

8681def Then(*ts, **ks):
8682 """Return a tactic that applies the tactics in `*ts` in sequence. Shorthand for AndThen(*ts, **ks).
8683
8684 >>> x, y = Ints('x y')
8685 >>> t = Then(Tactic('simplify'), Tactic('solve-eqs'))
8686 >>> t(And(x == 0, y > x + 1))
8687 [[Not(y <= 1)]]
8688 >>> t(And(x == 0, y > x + 1)).as_expr()
8689 Not(y <= 1)
8690 """
8691 return AndThen(*ts, **ks)
8692
8693

◆ to_Ast()

to_Ast (   ptr)

Definition at line 11764 of file z3py.py.

11764def to_Ast(ptr,):
11765 ast = Ast(ptr)
11766 super(ctypes.c_void_p, ast).__init__(ptr)
11767 return ast
11768

◆ to_AstVectorObj()

to_AstVectorObj (   ptr)

Definition at line 11774 of file z3py.py.

11774def to_AstVectorObj(ptr,):
11775 v = AstVectorObj(ptr)
11776 super(ctypes.c_void_p, v).__init__(ptr)
11777 return v
11778
11779# NB. my-hacky-class only works for a single instance of OnClause
11780# it should be replaced with a proper correlation between OnClause
11781# and object references that can be passed over the FFI.
11782# for UserPropagator we use a global dictionary, which isn't great code.
11783

◆ to_ContextObj()

to_ContextObj (   ptr)

Definition at line 11769 of file z3py.py.

11769def to_ContextObj(ptr,):
11770 ctx = ContextObj(ptr)
11771 super(ctypes.c_void_p, ctx).__init__(ptr)
11772 return ctx
11773

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

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

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

11757def TransitiveClosure(f):
11758 """Given a binary relation R, such that the two arguments have the same sort
11759 create the transitive closure relation R+.
11760 The transitive closure R+ is a new relation.
11761 """
11762 return FuncDeclRef(Z3_mk_transitive_closure(f.ctx_ref(), f.ast), f.ctx)
11763
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 11749 of file z3py.py.

11749def TreeOrder(a, index):
11750 return FuncDeclRef(Z3_mk_tree_order(a.ctx_ref(), a.ast, index), a.ctx)
11751
11752
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 8804 of file z3py.py.

8804def TryFor(t, ms, ctx=None):
8805 """Return a tactic that applies `t` to a given goal for `ms` milliseconds.
8806
8807 If `t` does not terminate in `ms` milliseconds, then it fails.
8808 """
8809 t = _to_tactic(t, ctx)
8810 return Tactic(Z3_tactic_try_for(t.ctx.ref(), t.tactic, ms), t.ctx)
8811
8812
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 5579 of file z3py.py.

5579def TupleSort(name, sorts, ctx=None):
5580 """Create a named tuple sort base on a set of underlying sorts
5581 Example:
5582 >>> pair, mk_pair, (first, second) = TupleSort("pair", [IntSort(), StringSort()])
5583 """
5584 tuple = Datatype(name, ctx)
5585 projects = [("project%d" % i, sorts[i]) for i in range(len(sorts))]
5586 tuple.declare(name, *projects)
5587 tuple = tuple.create()
5588 return tuple, tuple.constructor(0), [tuple.accessor(0, i) for i in range(len(sorts))]
5589
5590

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

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

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

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

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

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

11607def Union(*args):
11608 """Create union of regular expressions.
11609 >>> re = Union(Re("a"), Re("b"), Re("c"))
11610 >>> print (simplify(InRe("d", re)))
11611 False
11612 """
11613 args = _get_args(args)
11614 sz = len(args)
11615 if z3_debug():
11616 _z3_assert(sz > 0, "At least one argument expected.")
11617 _z3_assert(all([is_re(a) for a in args]), "All arguments must be regular expressions.")
11618 if sz == 1:
11619 return args[0]
11620 ctx = args[0].ctx
11621 v = (Ast * sz)()
11622 for i in range(sz):
11623 v[i] = args[i].as_ast()
11624 return ReRef(Z3_mk_re_union(ctx.ref(), sz, v), ctx)
11625
11626
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 11385 of file z3py.py.

11385def Unit(a):
11386 """Create a singleton sequence"""
11387 return SeqRef(Z3_mk_seq_unit(a.ctx_ref(), a.as_ast()), a.ctx)
11388
11389
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 4924 of file z3py.py.

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

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

11927def user_prop_binding(ctx, cb, q_ref, inst_ref):
11928 prop = _prop_closures.get(ctx)
11929 old_cb = prop.cb
11930 prop.cb = cb
11931 q = _to_expr_ref(to_Ast(q_ref), prop.ctx())
11932 inst = _to_expr_ref(to_Ast(inst_ref), prop.ctx())
11933 r = prop.binding(q, inst)
11934 prop.cb = old_cb
11935 return r
11936
11937

◆ user_prop_created()

user_prop_created (   ctx,
  cb,
  id 
)

Definition at line 11885 of file z3py.py.

11885def user_prop_created(ctx, cb, id):
11886 prop = _prop_closures.get(ctx)
11887 old_cb = prop.cb
11888 prop.cb = cb
11889 id = _to_expr_ref(to_Ast(id), prop.ctx())
11890 prop.created(id)
11891 prop.cb = old_cb
11892
11893

◆ user_prop_decide()

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

Definition at line 11919 of file z3py.py.

11919def user_prop_decide(ctx, cb, t_ref, idx, phase):
11920 prop = _prop_closures.get(ctx)
11921 old_cb = prop.cb
11922 prop.cb = cb
11923 t = _to_expr_ref(to_Ast(t_ref), prop.ctx())
11924 prop.decide(t, idx, phase)
11925 prop.cb = old_cb
11926

◆ user_prop_diseq()

user_prop_diseq (   ctx,
  cb,
  x,
  y 
)

Definition at line 11910 of file z3py.py.

11910def user_prop_diseq(ctx, cb, x, y):
11911 prop = _prop_closures.get(ctx)
11912 old_cb = prop.cb
11913 prop.cb = cb
11914 x = _to_expr_ref(to_Ast(x), prop.ctx())
11915 y = _to_expr_ref(to_Ast(y), prop.ctx())
11916 prop.diseq(x, y)
11917 prop.cb = old_cb
11918

◆ user_prop_eq()

user_prop_eq (   ctx,
  cb,
  x,
  y 
)

Definition at line 11901 of file z3py.py.

11901def user_prop_eq(ctx, cb, x, y):
11902 prop = _prop_closures.get(ctx)
11903 old_cb = prop.cb
11904 prop.cb = cb
11905 x = _to_expr_ref(to_Ast(x), prop.ctx())
11906 y = _to_expr_ref(to_Ast(y), prop.ctx())
11907 prop.eq(x, y)
11908 prop.cb = old_cb
11909

◆ user_prop_final()

user_prop_final (   ctx,
  cb 
)

Definition at line 11894 of file z3py.py.

11894def user_prop_final(ctx, cb):
11895 prop = _prop_closures.get(ctx)
11896 old_cb = prop.cb
11897 prop.cb = cb
11898 prop.final()
11899 prop.cb = old_cb
11900

◆ user_prop_fixed()

user_prop_fixed (   ctx,
  cb,
  id,
  value 
)

Definition at line 11876 of file z3py.py.

11876def user_prop_fixed(ctx, cb, id, value):
11877 prop = _prop_closures.get(ctx)
11878 old_cb = prop.cb
11879 prop.cb = cb
11880 id = _to_expr_ref(to_Ast(id), prop.ctx())
11881 value = _to_expr_ref(to_Ast(value), prop.ctx())
11882 prop.fixed(id, value)
11883 prop.cb = old_cb
11884

◆ user_prop_fresh()

user_prop_fresh (   ctx,
  _new_ctx 
)

Definition at line 11862 of file z3py.py.

11862def user_prop_fresh(ctx, _new_ctx):
11863 _prop_closures.set_threaded()
11864 prop = _prop_closures.get(ctx)
11865 nctx = Context()
11866 Z3_del_context(nctx.ctx)
11867 new_ctx = to_ContextObj(_new_ctx)
11868 nctx.ctx = new_ctx
11869 nctx.eh = Z3_set_error_handler(new_ctx, z3_error_handler)
11870 nctx.owner = False
11871 new_prop = prop.fresh(nctx)
11872 _prop_closures.set(new_prop.id, new_prop)
11873 return new_prop.id
11874
11875
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 11856 of file z3py.py.

11856def user_prop_pop(ctx, cb, num_scopes):
11857 prop = _prop_closures.get(ctx)
11858 prop.cb = cb
11859 prop.pop(num_scopes)
11860
11861

◆ user_prop_push()

user_prop_push (   ctx,
  cb 
)

Definition at line 11850 of file z3py.py.

11850def user_prop_push(ctx, cb):
11851 prop = _prop_closures.get(ctx)
11852 prop.cb = cb
11853 prop.push()
11854
11855

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

9098def When(p, t, ctx=None):
9099 """Return a tactic that applies tactic `t` only if probe `p` evaluates to true.
9100 Otherwise, it returns the input goal unmodified.
9101
9102 >>> t = When(Probe('size') > 2, Tactic('simplify'))
9103 >>> x, y = Ints('x y')
9104 >>> g = Goal()
9105 >>> g.add(x > 0)
9106 >>> g.add(y > 0)
9107 >>> t(g)
9108 [[x > 0, y > 0]]
9109 >>> g.add(x == y + 1)
9110 >>> t(g)
9111 [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
9112 """
9113 p = _to_probe(p, ctx)
9114 t = _to_tactic(t, ctx)
9115 return Tactic(Z3_tactic_when(t.ctx.ref(), p.probe, t.tactic), t.ctx)
9116
9117
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 8755 of file z3py.py.

8755def With(t, *args, **keys):
8756 """Return a tactic that applies tactic `t` using the given configuration options.
8757
8758 >>> x, y = Ints('x y')
8759 >>> t = With(Tactic('simplify'), som=True)
8760 >>> t((x + 1)*(y + 2) == 0)
8761 [[2*x + y + x*y == -2]]
8762 """
8763 ctx = keys.pop("ctx", None)
8764 t = _to_tactic(t, ctx)
8765 p = args2params(args, keys, t.ctx)
8766 return Tactic(Z3_tactic_using_params(t.ctx.ref(), t.tactic, p.params), t.ctx)
8767
8768
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 8769 of file z3py.py.

8769def WithParams(t, p):
8770 """Return a tactic that applies tactic `t` using the given configuration options.
8771
8772 >>> x, y = Ints('x y')
8773 >>> p = ParamsRef()
8774 >>> p.set("som", True)
8775 >>> t = WithParams(Tactic('simplify'), p)
8776 >>> t((x + 1)*(y + 2) == 0)
8777 [[2*x + y + x*y == -2]]
8778 """
8779 t = _to_tactic(t, None)
8780 return Tactic(Z3_tactic_using_params(t.ctx.ref(), t.tactic, p.params), t.ctx)
8781
8782

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

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

◆ _dflt_fpsort_sbits

int _dflt_fpsort_sbits = 53
protected

Definition at line 9651 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 9649 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 11784 of file z3py.py.

◆ _on_clause_eh

_on_clause_eh = Z3_on_clause_eh(on_clause_eh)
protected

Definition at line 11792 of file z3py.py.

◆ _on_model_eh

_on_model_eh = on_model_eh_type(_global_on_model)
protected

Definition at line 8152 of file z3py.py.

◆ _on_models

dict _on_models = {}
protected

Definition at line 8144 of file z3py.py.

◆ _prop_closures

_prop_closures = None
protected

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

◆ _user_prop_binding

_user_prop_binding = Z3_on_binding_eh(user_prop_binding)
protected

Definition at line 11947 of file z3py.py.

◆ _user_prop_created

_user_prop_created = Z3_created_eh(user_prop_created)
protected

Definition at line 11942 of file z3py.py.

◆ _user_prop_decide

_user_prop_decide = Z3_decide_eh(user_prop_decide)
protected

Definition at line 11946 of file z3py.py.

◆ _user_prop_diseq

_user_prop_diseq = Z3_eq_eh(user_prop_diseq)
protected

Definition at line 11945 of file z3py.py.

◆ _user_prop_eq

_user_prop_eq = Z3_eq_eh(user_prop_eq)
protected

Definition at line 11944 of file z3py.py.

◆ _user_prop_final

_user_prop_final = Z3_final_eh(user_prop_final)
protected

Definition at line 11943 of file z3py.py.

◆ _user_prop_fixed

_user_prop_fixed = Z3_fixed_eh(user_prop_fixed)
protected

Definition at line 11941 of file z3py.py.

◆ _user_prop_fresh

_user_prop_fresh = Z3_fresh_eh(user_prop_fresh)
protected

Definition at line 11940 of file z3py.py.

◆ _user_prop_pop

_user_prop_pop = Z3_pop_eh(user_prop_pop)
protected

Definition at line 11939 of file z3py.py.

◆ _user_prop_push

_user_prop_push = Z3_push_eh(user_prop_push)
protected

Definition at line 11938 of file z3py.py.

◆ sat

Definition at line 7141 of file z3py.py.

◆ unknown

Definition at line 7143 of file z3py.py.

◆ unsat

Definition at line 7142 of file z3py.py.

◆ Z3_DEBUG

Z3_DEBUG = __debug__

Definition at line 67 of file z3py.py.