Z3
 
Loading...
Searching...
No Matches
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)
 
 main_ctx ()
 
 _get_ctx (ctx)
 
 get_ctx (ctx)
 
 set_param (*args, **kws)
 
 reset_params ()
 
 set_option (*args, **kws)
 
 get_param (name)
 
 is_ast (a)
 
 eq (a, b)
 
 _ast_kind (ctx, 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.
 
 is_sort (s)
 
 _to_sort_ref (s, ctx)
 
 _sort (ctx, a)
 
 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)
 
 _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")
 
 Var (idx, s)
 
 RealVar (idx, ctx=None)
 
 RealVarVector (n, ctx=None)
 
 is_bool (a)
 
 is_true (a)
 
 is_false (a)
 
 is_and (a)
 
 is_or (a)
 
 is_implies (a)
 
 is_not (a)
 
 is_eq (a)
 
 is_distinct (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)
 
 is_arith_sort (s)
 
 is_arith (a)
 
 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)
 
 is_add (a)
 
 is_mul (a)
 
 is_sub (a)
 
 is_div (a)
 
 is_idiv (a)
 
 is_mod (a)
 
 is_le (a)
 
 is_lt (a)
 
 is_ge (a)
 
 is_gt (a)
 
 is_is_int (a)
 
 is_to_real (a)
 
 is_to_int (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)
 
 is_array (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)
 
 SetHasSize (a, k)
 
 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, 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)
 
 is_string (a)
 
 is_string_value (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)
 
 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)
 

Function Documentation

◆ _and_then()

_and_then ( t1,
t2,
ctx = None )
protected

Definition at line 8461 of file z3py.py.

8461def _and_then(t1, t2, ctx=None):
8462 t1 = _to_tactic(t1, ctx)
8463 t2 = _to_tactic(t2, ctx)
8464 if z3_debug():
8465 _z3_assert(t1.ctx == t2.ctx, "Context mismatch")
8466 return Tactic(Z3_tactic_and_then(t1.ctx.ref(), t1.tactic, t2.tactic), t1.ctx)
8467
8468
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 4651 of file z3py.py.

4651def _array_select(ar, arg):
4652 if isinstance(arg, tuple):
4653 args = [ar.sort().domain_n(i).cast(arg[i]) for i in range(len(arg))]
4654 _args, sz = _to_ast_array(args)
4655 return _to_expr_ref(Z3_mk_select_n(ar.ctx_ref(), ar.as_ast(), sz, _args), ar.ctx)
4656 arg = ar.sort().domain().cast(arg)
4657 return _to_expr_ref(Z3_mk_select(ar.ctx_ref(), ar.as_ast(), arg.as_ast()), ar.ctx)
4658
4659
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 ArrayRef.__getitem__(), and QuantifierRef.__getitem__().

◆ _ast_kind()

_ast_kind ( ctx,
a )
protected

Definition at line 491 of file z3py.py.

491def _ast_kind(ctx, a):
492 if is_ast(a):
493 a = a.as_ast()
494 return Z3_get_ast_kind(ctx.ref(), a)
495
496
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 4212 of file z3py.py.

4212def _check_bv_args(a, b):
4213 if z3_debug():
4214 _z3_assert(is_bv(a) or is_bv(b), "First or second argument must be a Z3 bit-vector expression")
4215
4216

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

10563def _check_fp_args(a, b):
10564 if z3_debug():
10565 _z3_assert(is_fp(a) or is_fp(b), "First or second argument must be a Z3 floating-point expression")
10566
10567

◆ _coerce_char()

_coerce_char ( ch,
ctx = None )
protected

Definition at line 11003 of file z3py.py.

11003def _coerce_char(ch, ctx=None):
11004 if isinstance(ch, str):
11005 ctx = _get_ctx(ctx)
11006 ch = CharVal(ch, ctx)
11007 if not is_expr(ch):
11008 raise Z3Exception("Character expression expected")
11009 return ch
11010

◆ _coerce_expr_list()

_coerce_expr_list ( alist,
ctx = None )
protected

Definition at line 1255 of file z3py.py.

1255def _coerce_expr_list(alist, ctx=None):
1256 has_expr = False
1257 for a in alist:
1258 if is_expr(a):
1259 has_expr = True
1260 break
1261 if not has_expr:
1262 alist = [_py2expr(a, ctx) for a in alist]
1263 s = _reduce(_coerce_expr_merge, alist, None)
1264 return [s.cast(a) for a in alist]
1265
1266

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

◆ _coerce_expr_merge()

_coerce_expr_merge ( s,
a )
protected

Definition at line 1208 of file z3py.py.

1208def _coerce_expr_merge(s, a):
1209 if is_expr(a):
1210 s1 = a.sort()
1211 if s is None:
1212 return s1
1213 if s1.eq(s):
1214 return s
1215 elif s.subsort(s1):
1216 return s1
1217 elif s1.subsort(s):
1218 return s
1219 else:
1220 if z3_debug():
1221 _z3_assert(s1.ctx == s.ctx, "context mismatch")
1222 _z3_assert(False, "sort mismatch")
1223 else:
1224 return s
1225
1226

Referenced by _coerce_exprs().

◆ _coerce_exprs()

_coerce_exprs ( a,
b,
ctx = None )
protected

Definition at line 1227 of file z3py.py.

1227def _coerce_exprs(a, b, ctx=None):
1228 if not is_expr(a) and not is_expr(b):
1229 a = _py2expr(a, ctx)
1230 b = _py2expr(b, ctx)
1231 if isinstance(a, str) and isinstance(b, SeqRef):
1232 a = StringVal(a, b.ctx)
1233 if isinstance(b, str) and isinstance(a, SeqRef):
1234 b = StringVal(b, a.ctx)
1235 if isinstance(a, float) and isinstance(b, ArithRef):
1236 a = RealVal(a, b.ctx)
1237 if isinstance(b, float) and isinstance(a, ArithRef):
1238 b = RealVal(b, a.ctx)
1239
1240 s = None
1241 s = _coerce_expr_merge(s, a)
1242 s = _coerce_expr_merge(s, b)
1243 a = s.cast(a)
1244 b = s.cast(b)
1245 return (a, b)
1246
1247

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

9522def _coerce_fp_expr_list(alist, ctx):
9523 first_fp_sort = None
9524 for a in alist:
9525 if is_fp(a):
9526 if first_fp_sort is None:
9527 first_fp_sort = a.sort()
9528 elif first_fp_sort == a.sort():
9529 pass # OK, same as before
9530 else:
9531 # we saw at least 2 different float sorts; something will
9532 # throw a sort mismatch later, for now assume None.
9533 first_fp_sort = None
9534 break
9535
9536 r = []
9537 for i in range(len(alist)):
9538 a = alist[i]
9539 is_repr = isinstance(a, str) and a.contains("2**(") and a.endswith(")")
9540 if is_repr or _is_int(a) or isinstance(a, (float, bool)):
9541 r.append(FPVal(a, None, first_fp_sort, ctx))
9542 else:
9543 r.append(a)
9544 return _coerce_expr_list(r, ctx)
9545
9546
9547# FP Sorts
9548

◆ _coerce_seq()

_coerce_seq ( s,
ctx = None )
protected

Definition at line 11053 of file z3py.py.

11053def _coerce_seq(s, ctx=None):
11054 if isinstance(s, str):
11055 ctx = _get_ctx(ctx)
11056 s = StringVal(s, ctx)
11057 if not is_expr(s):
11058 raise Z3Exception("Non-expression passed as a sequence")
11059 if not is_seq(s):
11060 raise Z3Exception("Non-sequence passed as a sequence")
11061 return s
11062
11063

Referenced by Concat().

◆ _ctx_from_ast_arg_list()

_ctx_from_ast_arg_list ( args,
default_ctx = None )
protected

Definition at line 497 of file z3py.py.

497def _ctx_from_ast_arg_list(args, default_ctx=None):
498 ctx = None
499 for a in args:
500 if is_ast(a) or is_probe(a):
501 if ctx is None:
502 ctx = a.ctx
503 else:
504 if z3_debug():
505 _z3_assert(ctx == a.ctx, "Context mismatch")
506 if ctx is None:
507 ctx = default_ctx
508 return ctx
509
510

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

511def _ctx_from_ast_args(*args):
512 return _ctx_from_ast_arg_list(args)
513
514

◆ _dflt_fps()

_dflt_fps ( ctx = None)
protected

Definition at line 9518 of file z3py.py.

9518def _dflt_fps(ctx=None):
9519 return get_default_fp_sort(ctx)
9520
9521

◆ _dflt_rm()

_dflt_rm ( ctx = None)
protected

Definition at line 9514 of file z3py.py.

9514def _dflt_rm(ctx=None):
9515 return get_default_rounding_mode(ctx)
9516
9517

◆ _dict2darray()

_dict2darray ( decls,
ctx )
protected

Definition at line 9387 of file z3py.py.

9387def _dict2darray(decls, ctx):
9388 sz = len(decls)
9389 _names = (Symbol * sz)()
9390 _decls = (FuncDecl * sz)()
9391 i = 0
9392 for k in decls:
9393 v = decls[k]
9394 if z3_debug():
9395 _z3_assert(isinstance(k, str), "String expected")
9396 _z3_assert(is_func_decl(v) or is_const(v), "Z3 declaration or constant expected")
9397 _names[i] = to_symbol(k, ctx)
9398 if is_const(v):
9399 _decls[i] = v.decl().ast
9400 else:
9401 _decls[i] = v.ast
9402 i = i + 1
9403 return sz, _names, _decls
9404

◆ _dict2sarray()

_dict2sarray ( sorts,
ctx )
protected

Definition at line 9371 of file z3py.py.

9371def _dict2sarray(sorts, ctx):
9372 sz = len(sorts)
9373 _names = (Symbol * sz)()
9374 _sorts = (Sort * sz)()
9375 i = 0
9376 for k in sorts:
9377 v = sorts[k]
9378 if z3_debug():
9379 _z3_assert(isinstance(k, str), "String expected")
9380 _z3_assert(is_sort(v), "Z3 sort expected")
9381 _names[i] = to_symbol(k, ctx)
9382 _sorts[i] = v.ast
9383 i = i + 1
9384 return sz, _names, _sorts
9385
9386

◆ _get_args()

_get_args ( args)
protected

Definition at line 144 of file z3py.py.

144def _get_args(args):
145 try:
146 if len(args) == 1 and (isinstance(args[0], tuple) or isinstance(args[0], list)):
147 return args[0]
148 elif len(args) == 1 and (isinstance(args[0], set) or isinstance(args[0], AstVector)):
149 return [arg for arg in args[0]]
150 else:
151 return args
152 except TypeError: # len is not necessarily defined when args is not a sequence (use reflection?)
153 return args
154
155# Use this when function takes multiple arguments
156
157

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

158def _get_args_ast_list(args):
159 try:
160 if isinstance(args, (set, AstVector, tuple)):
161 return [arg for arg in args]
162 else:
163 return args
164 except Exception:
165 return args
166
167

◆ _get_ctx()

_get_ctx ( ctx)
protected

◆ _get_ctx2()

_get_ctx2 ( a,
b,
ctx = None )
protected

Definition at line 11064 of file z3py.py.

11064def _get_ctx2(a, b, ctx=None):
11065 if is_expr(a):
11066 return a.ctx
11067 if is_expr(b):
11068 return b.ctx
11069 if ctx is None:
11070 ctx = main_ctx()
11071 return ctx
11072
11073

◆ _global_on_model()

_global_on_model ( ctx)
protected

Definition at line 7965 of file z3py.py.

7965def _global_on_model(ctx):
7966 (fn, mdl) = _on_models[ctx]
7967 fn(mdl)
7968
7969

◆ _has_probe()

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

Definition at line 1888 of file z3py.py.

1888def _has_probe(args):
1889 """Return `True` if one of the elements of the given collection is a Z3 probe."""
1890 for arg in args:
1891 if is_probe(arg):
1892 return True
1893 return False
1894
1895

Referenced by And(), and Or().

◆ _is_algebraic()

_is_algebraic ( ctx,
a )
protected

Definition at line 2785 of file z3py.py.

2785def _is_algebraic(ctx, a):
2786 return Z3_is_algebraic_number(ctx.ref(), a)
2787
2788
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 68 of file z3py.py.

68 def _is_int(v):
69 return isinstance(v, (int, long))

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

◆ _is_numeral()

_is_numeral ( ctx,
a )
protected

Definition at line 2781 of file z3py.py.

2781def _is_numeral(ctx, a):
2782 return Z3_is_numeral_ast(ctx.ref(), a)
2783
2784
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 1453 of file z3py.py.

1453def _mk_bin(f, a, b):
1454 args = (Ast * 2)()
1455 if z3_debug():
1456 _z3_assert(a.ctx == b.ctx, "Context mismatch")
1457 args[0] = a.as_ast()
1458 args[1] = b.as_ast()
1459 return f(a.ctx.ref(), 2, args)
1460
1461

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

10351def _mk_fp_bin(f, rm, a, b, ctx):
10352 ctx = _get_ctx(ctx)
10353 [a, b] = _coerce_fp_expr_list([a, b], ctx)
10354 if z3_debug():
10355 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
10356 _z3_assert(is_fp(a) or is_fp(b), "Second or third argument must be a Z3 floating-point expression")
10357 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast()), ctx)
10358
10359

◆ _mk_fp_bin_norm()

_mk_fp_bin_norm ( f,
a,
b,
ctx )
protected

Definition at line 10360 of file z3py.py.

10360def _mk_fp_bin_norm(f, a, b, ctx):
10361 ctx = _get_ctx(ctx)
10362 [a, b] = _coerce_fp_expr_list([a, b], ctx)
10363 if z3_debug():
10364 _z3_assert(is_fp(a) or is_fp(b), "First or second argument must be a Z3 floating-point expression")
10365 return FPRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
10366
10367

◆ _mk_fp_bin_pred()

_mk_fp_bin_pred ( f,
a,
b,
ctx )
protected

Definition at line 10368 of file z3py.py.

10368def _mk_fp_bin_pred(f, a, b, ctx):
10369 ctx = _get_ctx(ctx)
10370 [a, b] = _coerce_fp_expr_list([a, b], ctx)
10371 if z3_debug():
10372 _z3_assert(is_fp(a) or is_fp(b), "First or second argument must be a Z3 floating-point expression")
10373 return BoolRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
10374
10375

◆ _mk_fp_tern()

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

Definition at line 10376 of file z3py.py.

10376def _mk_fp_tern(f, rm, a, b, c, ctx):
10377 ctx = _get_ctx(ctx)
10378 [a, b, c] = _coerce_fp_expr_list([a, b, c], ctx)
10379 if z3_debug():
10380 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
10381 _z3_assert(is_fp(a) or is_fp(b) or is_fp(
10382 c), "Second, third or fourth argument must be a Z3 floating-point expression")
10383 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
10384
10385

◆ _mk_fp_unary()

_mk_fp_unary ( f,
rm,
a,
ctx )
protected

Definition at line 10334 of file z3py.py.

10334def _mk_fp_unary(f, rm, a, ctx):
10335 ctx = _get_ctx(ctx)
10336 [a] = _coerce_fp_expr_list([a], ctx)
10337 if z3_debug():
10338 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
10339 _z3_assert(is_fp(a), "Second argument must be a Z3 floating-point expression")
10340 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast()), ctx)
10341
10342

◆ _mk_fp_unary_pred()

_mk_fp_unary_pred ( f,
a,
ctx )
protected

Definition at line 10343 of file z3py.py.

10343def _mk_fp_unary_pred(f, a, ctx):
10344 ctx = _get_ctx(ctx)
10345 [a] = _coerce_fp_expr_list([a], ctx)
10346 if z3_debug():
10347 _z3_assert(is_fp(a), "First argument must be a Z3 floating-point expression")
10348 return BoolRef(f(ctx.ref(), a.as_ast()), ctx)
10349
10350

◆ _mk_quantifier()

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

Definition at line 2244 of file z3py.py.

2244def _mk_quantifier(is_forall, vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2245 if z3_debug():
2246 _z3_assert(is_bool(body) or is_app(vs) or (len(vs) > 0 and is_app(vs[0])), "Z3 expression expected")
2247 _z3_assert(is_const(vs) or (len(vs) > 0 and all([is_const(v) for v in vs])), "Invalid bounded variable(s)")
2248 _z3_assert(all([is_pattern(a) or is_expr(a) for a in patterns]), "Z3 patterns expected")
2249 _z3_assert(all([is_expr(p) for p in no_patterns]), "no patterns are Z3 expressions")
2250 if is_app(vs):
2251 ctx = vs.ctx
2252 vs = [vs]
2253 else:
2254 ctx = vs[0].ctx
2255 if not is_expr(body):
2256 body = BoolVal(body, ctx)
2257 num_vars = len(vs)
2258 if num_vars == 0:
2259 return body
2260 _vs = (Ast * num_vars)()
2261 for i in range(num_vars):
2262 # TODO: Check if is constant
2263 _vs[i] = vs[i].as_ast()
2264 patterns = [_to_pattern(p) for p in patterns]
2265 num_pats = len(patterns)
2266 _pats = (Pattern * num_pats)()
2267 for i in range(num_pats):
2268 _pats[i] = patterns[i].ast
2269 _no_pats, num_no_pats = _to_ast_array(no_patterns)
2270 qid = to_symbol(qid, ctx)
2271 skid = to_symbol(skid, ctx)
2272 return QuantifierRef(Z3_mk_quantifier_const_ex(ctx.ref(), is_forall, weight, qid, skid,
2273 num_vars, _vs,
2274 num_pats, _pats,
2275 num_no_pats, _no_pats,
2276 body.as_ast()), ctx)
2277
2278
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 8469 of file z3py.py.

8469def _or_else(t1, t2, ctx=None):
8470 t1 = _to_tactic(t1, ctx)
8471 t2 = _to_tactic(t2, ctx)
8472 if z3_debug():
8473 _z3_assert(t1.ctx == t2.ctx, "Context mismatch")
8474 return Tactic(Z3_tactic_or_else(t1.ctx.ref(), t1.tactic, t2.tactic), t1.ctx)
8475
8476
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 9160 of file z3py.py.

9160def _pb_args_coeffs(args, default_ctx=None):
9161 args = _get_args_ast_list(args)
9162 if len(args) == 0:
9163 return _get_ctx(default_ctx), 0, (Ast * 0)(), (ctypes.c_int * 0)()
9164 args = [_reorder_pb_arg(arg) for arg in args]
9165 args, coeffs = zip(*args)
9166 if z3_debug():
9167 _z3_assert(len(args) > 0, "Non empty list of arguments expected")
9168 ctx = _ctx_from_ast_arg_list(args)
9169 if z3_debug():
9170 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
9171 args = _coerce_expr_list(args, ctx)
9172 _args, sz = _to_ast_array(args)
9173 _coeffs = (ctypes.c_int * len(coeffs))()
9174 for i in range(len(coeffs)):
9175 _z3_check_cint_overflow(coeffs[i], "coefficient")
9176 _coeffs[i] = coeffs[i]
9177 return ctx, sz, _args, _coeffs, args
9178
9179

◆ _probe_and()

_probe_and ( args,
ctx )
protected

Definition at line 8884 of file z3py.py.

8884def _probe_and(args, ctx):
8885 return _probe_nary(Z3_probe_and, args, ctx)
8886
8887

Referenced by And().

◆ _probe_nary()

_probe_nary ( f,
args,
ctx )
protected

Definition at line 8874 of file z3py.py.

8874def _probe_nary(f, args, ctx):
8875 if z3_debug():
8876 _z3_assert(len(args) > 0, "At least one argument expected")
8877 num = len(args)
8878 r = _to_probe(args[0], ctx)
8879 for i in range(num - 1):
8880 r = Probe(f(ctx.ref(), r.probe, _to_probe(args[i + 1], ctx).probe), ctx)
8881 return r
8882
8883

◆ _probe_or()

_probe_or ( args,
ctx )
protected

Definition at line 8888 of file z3py.py.

8888def _probe_or(args, ctx):
8889 return _probe_nary(Z3_probe_or, args, ctx)
8890
8891

Referenced by Or().

◆ _prove_html()

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

Definition at line 9351 of file z3py.py.

9351def _prove_html(claim, show=False, **keywords):
9352 """Version of function `prove` that renders HTML."""
9353 if z3_debug():
9354 _z3_assert(is_bool(claim), "Z3 Boolean expression expected")
9355 s = Solver()
9356 s.set(**keywords)
9357 s.add(Not(claim))
9358 if show:
9359 print(s)
9360 r = s.check()
9361 if r == unsat:
9362 print("<b>proved</b>")
9363 elif r == unknown:
9364 print("<b>failed to prove</b>")
9365 print(s.model())
9366 else:
9367 print("<b>counterexample</b>")
9368 print(s.model())
9369
9370

◆ _py2expr()

_py2expr ( a,
ctx = None )
protected

Definition at line 3180 of file z3py.py.

3180def _py2expr(a, ctx=None):
3181 if isinstance(a, bool):
3182 return BoolVal(a, ctx)
3183 if _is_int(a):
3184 return IntVal(a, ctx)
3185 if isinstance(a, float):
3186 return RealVal(a, ctx)
3187 if isinstance(a, str):
3188 return StringVal(a, ctx)
3189 if is_expr(a):
3190 return a
3191 if z3_debug():
3192 _z3_assert(False, "Python bool, int, long or float expected")
3193
3194

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

◆ _reduce()

_reduce ( func,
sequence,
initial )
protected

Definition at line 1248 of file z3py.py.

1248def _reduce(func, sequence, initial):
1249 result = initial
1250 for element in sequence:
1251 result = func(result, element)
1252 return result
1253
1254

Referenced by _coerce_expr_list().

◆ _reorder_pb_arg()

_reorder_pb_arg ( arg)
protected

Definition at line 9153 of file z3py.py.

9153def _reorder_pb_arg(arg):
9154 a, b = arg
9155 if not _is_int(b) and _is_int(a):
9156 return b, a
9157 return arg
9158
9159

◆ _solve_html()

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

Definition at line 9302 of file z3py.py.

9302def _solve_html(*args, **keywords):
9303 """Version of function `solve` that renders HTML output."""
9304 show = keywords.pop("show", False)
9305 s = Solver()
9306 s.set(**keywords)
9307 s.add(*args)
9308 if show:
9309 print("<b>Problem:</b>")
9310 print(s)
9311 r = s.check()
9312 if r == unsat:
9313 print("<b>no solution</b>")
9314 elif r == unknown:
9315 print("<b>failed to solve</b>")
9316 try:
9317 print(s.model())
9318 except Z3Exception:
9319 return
9320 else:
9321 if show:
9322 print("<b>Solution:</b>")
9323 print(s.model())
9324
9325

◆ _solve_using_html()

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

Definition at line 9326 of file z3py.py.

9326def _solve_using_html(s, *args, **keywords):
9327 """Version of function `solve_using` that renders HTML."""
9328 show = keywords.pop("show", False)
9329 if z3_debug():
9330 _z3_assert(isinstance(s, Solver), "Solver object expected")
9331 s.set(**keywords)
9332 s.add(*args)
9333 if show:
9334 print("<b>Problem:</b>")
9335 print(s)
9336 r = s.check()
9337 if r == unsat:
9338 print("<b>no solution</b>")
9339 elif r == unknown:
9340 print("<b>failed to solve</b>")
9341 try:
9342 print(s.model())
9343 except Z3Exception:
9344 return
9345 else:
9346 if show:
9347 print("<b>Solution:</b>")
9348 print(s.model())
9349
9350

◆ _sort()

_sort ( ctx,
a )
protected

Definition at line 691 of file z3py.py.

691def _sort(ctx, a):
692 return _to_sort_ref(Z3_get_sort(ctx.ref(), a), ctx)
693
694
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.

◆ _sort_kind()

_sort_kind ( ctx,
s )
protected

Sorts.

Definition at line 555 of file z3py.py.

555def _sort_kind(ctx, s):
556 return Z3_get_sort_kind(ctx.ref(), s)
557
558
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 132 of file z3py.py.

132def _symbol2py(ctx, s):
133 """Convert a Z3 symbol back into a Python object. """
134 if Z3_get_symbol_kind(ctx.ref(), s) == Z3_INT_SYMBOL:
135 return "k!%s" % Z3_get_symbol_int(ctx.ref(), s)
136 else:
137 return Z3_get_symbol_string(ctx.ref(), s)
138
139# Hack for having nary functions that can receive one argument that is the
140# list of arguments.
141# Use this when function takes a single list of arguments
142
143
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 523 of file z3py.py.

523def _to_ast_array(args):
524 sz = len(args)
525 _args = (Ast * sz)()
526 for i in range(sz):
527 _args[i] = args[i].as_ast()
528 return _args, sz
529
530

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

539def _to_ast_ref(a, ctx):
540 k = _ast_kind(ctx, a)
541 if k == Z3_SORT_AST:
542 return _to_sort_ref(a, ctx)
543 elif k == Z3_FUNC_DECL_AST:
544 return _to_func_decl_ref(a, ctx)
545 else:
546 return _to_expr_ref(a, ctx)
547
548

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

◆ _to_expr_ref()

_to_expr_ref ( a,
ctx )
protected

Definition at line 1158 of file z3py.py.

1158def _to_expr_ref(a, ctx):
1159 if isinstance(a, Pattern):
1160 return PatternRef(a, ctx)
1161 ctx_ref = ctx.ref()
1162 k = Z3_get_ast_kind(ctx_ref, a)
1163 if k == Z3_QUANTIFIER_AST:
1164 return QuantifierRef(a, ctx)
1165 sk = Z3_get_sort_kind(ctx_ref, Z3_get_sort(ctx_ref, a))
1166 if sk == Z3_BOOL_SORT:
1167 return BoolRef(a, ctx)
1168 if sk == Z3_INT_SORT:
1169 if k == Z3_NUMERAL_AST:
1170 return IntNumRef(a, ctx)
1171 return ArithRef(a, ctx)
1172 if sk == Z3_REAL_SORT:
1173 if k == Z3_NUMERAL_AST:
1174 return RatNumRef(a, ctx)
1175 if _is_algebraic(ctx, a):
1176 return AlgebraicNumRef(a, ctx)
1177 return ArithRef(a, ctx)
1178 if sk == Z3_BV_SORT:
1179 if k == Z3_NUMERAL_AST:
1180 return BitVecNumRef(a, ctx)
1181 else:
1182 return BitVecRef(a, ctx)
1183 if sk == Z3_ARRAY_SORT:
1184 return ArrayRef(a, ctx)
1185 if sk == Z3_DATATYPE_SORT:
1186 return DatatypeRef(a, ctx)
1187 if sk == Z3_FLOATING_POINT_SORT:
1188 if k == Z3_APP_AST and _is_numeral(ctx, a):
1189 return FPNumRef(a, ctx)
1190 else:
1191 return FPRef(a, ctx)
1192 if sk == Z3_FINITE_DOMAIN_SORT:
1193 if k == Z3_NUMERAL_AST:
1194 return FiniteDomainNumRef(a, ctx)
1195 else:
1196 return FiniteDomainRef(a, ctx)
1197 if sk == Z3_ROUNDING_MODE_SORT:
1198 return FPRMRef(a, ctx)
1199 if sk == Z3_SEQ_SORT:
1200 return SeqRef(a, ctx)
1201 if sk == Z3_CHAR_SORT:
1202 return CharRef(a, ctx)
1203 if sk == Z3_RE_SORT:
1204 return ReRef(a, ctx)
1205 return ExprRef(a, ctx)
1206
1207

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

◆ _to_float_str()

_to_float_str ( val,
exp = 0 )
protected

Definition at line 10096 of file z3py.py.

10096def _to_float_str(val, exp=0):
10097 if isinstance(val, float):
10098 if math.isnan(val):
10099 res = "NaN"
10100 elif val == 0.0:
10101 sone = math.copysign(1.0, val)
10102 if sone < 0.0:
10103 return "-0.0"
10104 else:
10105 return "+0.0"
10106 elif val == float("+inf"):
10107 res = "+oo"
10108 elif val == float("-inf"):
10109 res = "-oo"
10110 else:
10111 v = val.as_integer_ratio()
10112 num = v[0]
10113 den = v[1]
10114 rvs = str(num) + "/" + str(den)
10115 res = rvs + "p" + _to_int_str(exp)
10116 elif isinstance(val, bool):
10117 if val:
10118 res = "1.0"
10119 else:
10120 res = "0.0"
10121 elif _is_int(val):
10122 res = str(val)
10123 elif isinstance(val, str):
10124 inx = val.find("*(2**")
10125 if inx == -1:
10126 res = val
10127 elif val[-1] == ")":
10128 res = val[0:inx]
10129 exp = str(int(val[inx + 5:-1]) + int(exp))
10130 else:
10131 _z3_assert(False, "String does not have floating-point numeral form.")
10132 elif z3_debug():
10133 _z3_assert(False, "Python value cannot be used to create floating-point numerals.")
10134 if exp == 0:
10135 return res
10136 else:
10137 return res + "p" + exp
10138
10139

◆ _to_func_decl_array()

_to_func_decl_array ( args)
protected

Definition at line 515 of file z3py.py.

515def _to_func_decl_array(args):
516 sz = len(args)
517 _args = (FuncDecl * sz)()
518 for i in range(sz):
519 _args[i] = args[i].as_func_decl()
520 return _args, sz
521
522

◆ _to_func_decl_ref()

_to_func_decl_ref ( a,
ctx )
protected

Definition at line 923 of file z3py.py.

923def _to_func_decl_ref(a, ctx):
924 return FuncDeclRef(a, ctx)
925
926

Referenced by _to_ast_ref().

◆ _to_goal()

_to_goal ( a)
protected

Definition at line 8445 of file z3py.py.

8445def _to_goal(a):
8446 if isinstance(a, BoolRef):
8447 goal = Goal(ctx=a.ctx)
8448 goal.add(a)
8449 return goal
8450 else:
8451 return a
8452
8453

◆ _to_int_str()

_to_int_str ( val)
protected

Definition at line 3229 of file z3py.py.

3229def _to_int_str(val):
3230 if isinstance(val, float):
3231 return str(int(val))
3232 elif isinstance(val, bool):
3233 if val:
3234 return "1"
3235 else:
3236 return "0"
3237 else:
3238 return str(val)
3239
3240

Referenced by BitVecVal(), and IntVal().

◆ _to_param_value()

_to_param_value ( val)
protected

Definition at line 168 of file z3py.py.

168def _to_param_value(val):
169 if isinstance(val, bool):
170 return "true" if val else "false"
171 return str(val)
172
173

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

◆ _to_pattern()

_to_pattern ( arg)
protected

Definition at line 2022 of file z3py.py.

2022def _to_pattern(arg):
2023 if is_pattern(arg):
2024 return arg
2025 else:
2026 return MultiPattern(arg)
2027

Referenced by _mk_quantifier().

◆ _to_probe()

_to_probe ( p,
ctx = None )
protected

Definition at line 8828 of file z3py.py.

8828def _to_probe(p, ctx=None):
8829 if is_probe(p):
8830 return p
8831 else:
8832 return Probe(p, ctx)
8833
8834

◆ _to_ref_array()

_to_ref_array ( ref,
args )
protected

Definition at line 531 of file z3py.py.

531def _to_ref_array(ref, args):
532 sz = len(args)
533 _args = (ref * sz)()
534 for i in range(sz):
535 _args[i] = args[i].as_ast()
536 return _args, sz
537
538

◆ _to_sort_ref()

_to_sort_ref ( s,
ctx )
protected

Definition at line 660 of file z3py.py.

660def _to_sort_ref(s, ctx):
661 if z3_debug():
662 _z3_assert(isinstance(s, Sort), "Z3 Sort expected")
663 k = _sort_kind(ctx, s)
664 if k == Z3_BOOL_SORT:
665 return BoolSortRef(s, ctx)
666 elif k == Z3_INT_SORT or k == Z3_REAL_SORT:
667 return ArithSortRef(s, ctx)
668 elif k == Z3_BV_SORT:
669 return BitVecSortRef(s, ctx)
670 elif k == Z3_ARRAY_SORT:
671 return ArraySortRef(s, ctx)
672 elif k == Z3_DATATYPE_SORT:
673 return DatatypeSortRef(s, ctx)
674 elif k == Z3_FINITE_DOMAIN_SORT:
675 return FiniteDomainSortRef(s, ctx)
676 elif k == Z3_FLOATING_POINT_SORT:
677 return FPSortRef(s, ctx)
678 elif k == Z3_ROUNDING_MODE_SORT:
679 return FPRMSortRef(s, ctx)
680 elif k == Z3_RE_SORT:
681 return ReSortRef(s, ctx)
682 elif k == Z3_SEQ_SORT:
683 return SeqSortRef(s, ctx)
684 elif k == Z3_CHAR_SORT:
685 return CharSortRef(s, ctx)
686 elif k == Z3_TYPE_VAR:
687 return TypeVarRef(s, ctx)
688 return SortRef(s, ctx)
689
690

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

◆ _to_tactic()

_to_tactic ( t,
ctx = None )
protected

Definition at line 8454 of file z3py.py.

8454def _to_tactic(t, ctx=None):
8455 if isinstance(t, Tactic):
8456 return t
8457 else:
8458 return Tactic(t, ctx)
8459
8460

◆ _valid_accessor()

_valid_accessor ( acc)
protected

Datatypes.

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

Definition at line 5090 of file z3py.py.

5090def _valid_accessor(acc):
5091 """Return `True` if acc is pair of the form (String, Datatype or Sort). """
5092 if not isinstance(acc, tuple):
5093 return False
5094 if len(acc) != 2:
5095 return False
5096 return isinstance(acc[0], str) and (isinstance(acc[1], Datatype) or is_sort(acc[1]))
5097
5098

Referenced by Datatype.declare_core().

◆ _z3_assert()

◆ _z3_check_cint_overflow()

_z3_check_cint_overflow ( n,
name )
protected

Definition at line 110 of file z3py.py.

110def _z3_check_cint_overflow(n, name):
111 _z3_assert(ctypes.c_int(n).value == n, name + " is too large")
112
113

◆ Abs()

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

Definition at line 9112 of file z3py.py.

9112def Abs(arg):
9113 """Create the absolute value of an arithmetic expression"""
9114 return If(arg > 0, arg, -arg)
9115
9116

◆ AllChar()

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

Definition at line 11518 of file z3py.py.

11518def AllChar(regex_sort, ctx=None):
11519 """Create a regular expression that accepts all single character strings
11520 """
11521 return ReRef(Z3_mk_re_allchar(regex_sort.ctx_ref(), regex_sort.ast), regex_sort.ctx)
11522
11523# Special Relations
11524
11525
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 1896 of file z3py.py.

1896def And(*args):
1897 """Create a Z3 and-expression or and-probe.
1898
1899 >>> p, q, r = Bools('p q r')
1900 >>> And(p, q, r)
1901 And(p, q, r)
1902 >>> P = BoolVector('p', 5)
1903 >>> And(P)
1904 And(p__0, p__1, p__2, p__3, p__4)
1905 """
1906 last_arg = None
1907 if len(args) > 0:
1908 last_arg = args[len(args) - 1]
1909 if isinstance(last_arg, Context):
1910 ctx = args[len(args) - 1]
1911 args = args[:len(args) - 1]
1912 elif len(args) == 1 and isinstance(args[0], AstVector):
1913 ctx = args[0].ctx
1914 args = [a for a in args[0]]
1915 else:
1916 ctx = None
1917 args = _get_args(args)
1918 ctx = _get_ctx(_ctx_from_ast_arg_list(args, ctx))
1919 if z3_debug():
1920 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression or probe")
1921 if _has_probe(args):
1922 return _probe_and(args, ctx)
1923 else:
1924 args = _coerce_expr_list(args, ctx)
1925 _args, sz = _to_ast_array(args)
1926 return BoolRef(Z3_mk_and(ctx.ref(), sz, _args), ctx)
1927
1928
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 8477 of file z3py.py.

8477def AndThen(*ts, **ks):
8478 """Return a tactic that applies the tactics in `*ts` in sequence.
8479
8480 >>> x, y = Ints('x y')
8481 >>> t = AndThen(Tactic('simplify'), Tactic('solve-eqs'))
8482 >>> t(And(x == 0, y > x + 1))
8483 [[Not(y <= 1)]]
8484 >>> t(And(x == 0, y > x + 1)).as_expr()
8485 Not(y <= 1)
8486 """
8487 if z3_debug():
8488 _z3_assert(len(ts) >= 2, "At least two arguments expected")
8489 ctx = ks.get("ctx", None)
8490 num = len(ts)
8491 r = ts[0]
8492 for i in range(num - 1):
8493 r = _and_then(r, ts[i + 1], ctx)
8494 return r
8495
8496

◆ append_log()

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

Definition at line 119 of file z3py.py.

119def append_log(s):
120 """Append user-defined string to interaction log. """
122
123
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 5519 of file z3py.py.

5519def args2params(arguments, keywords, ctx=None):
5520 """Convert python arguments into a Z3_params object.
5521 A ':' is added to the keywords, and '_' is replaced with '-'
5522
5523 >>> args2params(['model', True, 'relevancy', 2], {'elim_and' : True})
5524 (params model true relevancy 2 elim_and true)
5525 """
5526 if z3_debug():
5527 _z3_assert(len(arguments) % 2 == 0, "Argument list must have an even number of elements.")
5528 prev = None
5529 r = ParamsRef(ctx)
5530 for a in arguments:
5531 if prev is None:
5532 prev = a
5533 else:
5534 r.set(prev, a)
5535 prev = None
5536 for k in keywords:
5537 v = keywords[k]
5538 r.set(k, v)
5539 return r
5540
5541

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

4786def Array(name, *sorts):
4787 """Return an array constant named `name` with the given domain and range sorts.
4788
4789 >>> a = Array('a', IntSort(), IntSort())
4790 >>> a.sort()
4791 Array(Int, Int)
4792 >>> a[0]
4793 a[0]
4794 """
4795 s = ArraySort(sorts)
4796 ctx = s.ctx
4797 return ArrayRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), s.ast), ctx)
4798
4799
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 4753 of file z3py.py.

4753def ArraySort(*sig):
4754 """Return the Z3 array sort with the given domain and range sorts.
4755
4756 >>> A = ArraySort(IntSort(), BoolSort())
4757 >>> A
4758 Array(Int, Bool)
4759 >>> A.domain()
4760 Int
4761 >>> A.range()
4762 Bool
4763 >>> AA = ArraySort(IntSort(), A)
4764 >>> AA
4765 Array(Int, Array(Int, Bool))
4766 """
4767 sig = _get_args(sig)
4768 if z3_debug():
4769 _z3_assert(len(sig) > 1, "At least two arguments expected")
4770 arity = len(sig) - 1
4771 r = sig[arity]
4772 d = sig[0]
4773 if z3_debug():
4774 for s in sig:
4775 _z3_assert(is_sort(s), "Z3 sort expected")
4776 _z3_assert(s.ctx == r.ctx, "Context mismatch")
4777 ctx = d.ctx
4778 if len(sig) == 2:
4779 return ArraySortRef(Z3_mk_array_sort(ctx.ref(), d.ast, r.ast), ctx)
4780 dom = (Sort * arity)()
4781 for i in range(arity):
4782 dom[i] = sig[i].ast
4783 return ArraySortRef(Z3_mk_array_sort_n(ctx.ref(), arity, dom, r.ast), ctx)
4784
4785
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 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 9135 of file z3py.py.

9135def AtLeast(*args):
9136 """Create an at-least Pseudo-Boolean k constraint.
9137
9138 >>> a, b, c = Bools('a b c')
9139 >>> f = AtLeast(a, b, c, 2)
9140 """
9141 args = _get_args(args)
9142 if z3_debug():
9143 _z3_assert(len(args) > 1, "Non empty list of arguments expected")
9144 ctx = _ctx_from_ast_arg_list(args)
9145 if z3_debug():
9146 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
9147 args1 = _coerce_expr_list(args[:-1], ctx)
9148 k = args[-1]
9149 _args, sz = _to_ast_array(args1)
9150 return BoolRef(Z3_mk_atleast(ctx.ref(), sz, _args, k), ctx)
9151
9152
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 9117 of file z3py.py.

9117def AtMost(*args):
9118 """Create an at-most Pseudo-Boolean k constraint.
9119
9120 >>> a, b, c = Bools('a b c')
9121 >>> f = AtMost(a, b, c, 2)
9122 """
9123 args = _get_args(args)
9124 if z3_debug():
9125 _z3_assert(len(args) > 1, "Non empty list of arguments expected")
9126 ctx = _ctx_from_ast_arg_list(args)
9127 if z3_debug():
9128 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
9129 args1 = _coerce_expr_list(args[:-1], ctx)
9130 k = args[-1]
9131 _args, sz = _to_ast_array(args1)
9132 return BoolRef(Z3_mk_atmost(ctx.ref(), sz, _args, k), ctx)
9133
9134
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 4090 of file z3py.py.

4090def BitVec(name, bv, ctx=None):
4091 """Return a bit-vector constant named `name`. `bv` may be the number of bits of a bit-vector sort.
4092 If `ctx=None`, then the global context is used.
4093
4094 >>> x = BitVec('x', 16)
4095 >>> is_bv(x)
4096 True
4097 >>> x.size()
4098 16
4099 >>> x.sort()
4100 BitVec(16)
4101 >>> word = BitVecSort(16)
4102 >>> x2 = BitVec('x', word)
4103 >>> eq(x, x2)
4104 True
4105 """
4106 if isinstance(bv, BitVecSortRef):
4107 ctx = bv.ctx
4108 else:
4109 ctx = _get_ctx(ctx)
4110 bv = BitVecSort(bv, ctx)
4111 return BitVecRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), bv.ast), ctx)
4112
4113

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

4114def BitVecs(names, bv, ctx=None):
4115 """Return a tuple of bit-vector constants of size bv.
4116
4117 >>> x, y, z = BitVecs('x y z', 16)
4118 >>> x.size()
4119 16
4120 >>> x.sort()
4121 BitVec(16)
4122 >>> Sum(x, y, z)
4123 0 + x + y + z
4124 >>> Product(x, y, z)
4125 1*x*y*z
4126 >>> simplify(Product(x, y, z))
4127 x*y*z
4128 """
4129 ctx = _get_ctx(ctx)
4130 if isinstance(names, str):
4131 names = names.split(" ")
4132 return [BitVec(name, bv, ctx) for name in names]
4133
4134

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

4058def BitVecSort(sz, ctx=None):
4059 """Return a Z3 bit-vector sort of the given size. If `ctx=None`, then the global context is used.
4060
4061 >>> Byte = BitVecSort(8)
4062 >>> Word = BitVecSort(16)
4063 >>> Byte
4064 BitVec(8)
4065 >>> x = Const('x', Byte)
4066 >>> eq(x, BitVec('x', 8))
4067 True
4068 """
4069 ctx = _get_ctx(ctx)
4070 return BitVecSortRef(Z3_mk_bv_sort(ctx.ref(), sz), ctx)
4071
4072
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 4073 of file z3py.py.

4073def BitVecVal(val, bv, ctx=None):
4074 """Return a bit-vector value with the given number of bits. If `ctx=None`, then the global context is used.
4075
4076 >>> v = BitVecVal(10, 32)
4077 >>> v
4078 10
4079 >>> print("0x%.8x" % v.as_long())
4080 0x0000000a
4081 """
4082 if is_bv_sort(bv):
4083 ctx = bv.ctx
4084 return BitVecNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), bv.ast), ctx)
4085 else:
4086 ctx = _get_ctx(ctx)
4087 return BitVecNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), BitVecSort(bv, ctx).ast), ctx)
4088
4089
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 1775 of file z3py.py.

1775def Bool(name, ctx=None):
1776 """Return a Boolean constant named `name`. If `ctx=None`, then the global context is used.
1777
1778 >>> p = Bool('p')
1779 >>> q = Bool('q')
1780 >>> And(p, q)
1781 And(p, q)
1782 """
1783 ctx = _get_ctx(ctx)
1784 return BoolRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), BoolSort(ctx).ast), ctx)
1785
1786

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

1787def Bools(names, ctx=None):
1788 """Return a tuple of Boolean constants.
1789
1790 `names` is a single string containing all names separated by blank spaces.
1791 If `ctx=None`, then the global context is used.
1792
1793 >>> p, q, r = Bools('p q r')
1794 >>> And(p, Or(q, r))
1795 And(p, Or(q, r))
1796 """
1797 ctx = _get_ctx(ctx)
1798 if isinstance(names, str):
1799 names = names.split(" ")
1800 return [Bool(name, ctx) for name in names]
1801
1802

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

1738def BoolSort(ctx=None):
1739 """Return the Boolean Z3 sort. If `ctx=None`, then the global context is used.
1740
1741 >>> BoolSort()
1742 Bool
1743 >>> p = Const('p', BoolSort())
1744 >>> is_bool(p)
1745 True
1746 >>> r = Function('r', IntSort(), IntSort(), BoolSort())
1747 >>> r(0, 1)
1748 r(0, 1)
1749 >>> is_bool(r(0, 1))
1750 True
1751 """
1752 ctx = _get_ctx(ctx)
1753 return BoolSortRef(Z3_mk_bool_sort(ctx.ref()), ctx)
1754
1755
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 1756 of file z3py.py.

1756def BoolVal(val, ctx=None):
1757 """Return the Boolean value `True` or `False`. If `ctx=None`, then the global context is used.
1758
1759 >>> BoolVal(True)
1760 True
1761 >>> is_true(BoolVal(True))
1762 True
1763 >>> is_true(True)
1764 False
1765 >>> is_false(BoolVal(False))
1766 True
1767 """
1768 ctx = _get_ctx(ctx)
1769 if val:
1770 return BoolRef(Z3_mk_true(ctx.ref()), ctx)
1771 else:
1772 return BoolRef(Z3_mk_false(ctx.ref()), ctx)
1773
1774
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 1803 of file z3py.py.

1803def BoolVector(prefix, sz, ctx=None):
1804 """Return a list of Boolean constants of size `sz`.
1805
1806 The constants are named using the given prefix.
1807 If `ctx=None`, then the global context is used.
1808
1809 >>> P = BoolVector('p', 3)
1810 >>> P
1811 [p__0, p__1, p__2]
1812 >>> And(P)
1813 And(p__0, p__1, p__2)
1814 """
1815 return [Bool("%s__%s" % (prefix, i)) for i in range(sz)]
1816
1817

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

4026def BV2Int(a, is_signed=False):
4027 """Return the Z3 expression BV2Int(a).
4028
4029 >>> b = BitVec('b', 3)
4030 >>> BV2Int(b).sort()
4031 Int
4032 >>> x = Int('x')
4033 >>> x > BV2Int(b)
4034 x > BV2Int(b)
4035 >>> x > BV2Int(b, is_signed=False)
4036 x > BV2Int(b)
4037 >>> x > BV2Int(b, is_signed=True)
4038 x > If(b < 0, BV2Int(b) - 8, BV2Int(b))
4039 >>> solve(x > BV2Int(b), b == 1, x < 3)
4040 [x = 2, b = 1]
4041 """
4042 if z3_debug():
4043 _z3_assert(is_bv(a), "First argument must be a Z3 bit-vector expression")
4044 ctx = a.ctx
4045 # investigate problem with bv2int
4046 return ArithRef(Z3_mk_bv2int(ctx.ref(), a.as_ast(), is_signed), ctx)
4047
4048
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 4512 of file z3py.py.

4512def BVAddNoOverflow(a, b, signed):
4513 """A predicate the determines that bit-vector addition does not overflow"""
4514 _check_bv_args(a, b)
4515 a, b = _coerce_exprs(a, b)
4516 return BoolRef(Z3_mk_bvadd_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast(), signed), a.ctx)
4517
4518
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 4519 of file z3py.py.

4519def BVAddNoUnderflow(a, b):
4520 """A predicate the determines that signed bit-vector addition does not underflow"""
4521 _check_bv_args(a, b)
4522 a, b = _coerce_exprs(a, b)
4523 return BoolRef(Z3_mk_bvadd_no_underflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4524
4525
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 4554 of file z3py.py.

4554def BVMulNoOverflow(a, b, signed):
4555 """A predicate the determines that bit-vector multiplication does not overflow"""
4556 _check_bv_args(a, b)
4557 a, b = _coerce_exprs(a, b)
4558 return BoolRef(Z3_mk_bvmul_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast(), signed), a.ctx)
4559
4560
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 4561 of file z3py.py.

4561def BVMulNoUnderflow(a, b):
4562 """A predicate the determines that bit-vector signed multiplication does not underflow"""
4563 _check_bv_args(a, b)
4564 a, b = _coerce_exprs(a, b)
4565 return BoolRef(Z3_mk_bvmul_no_underflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4566
4567
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 4498 of file z3py.py.

4498def BVRedAnd(a):
4499 """Return the reduction-and expression of `a`."""
4500 if z3_debug():
4501 _z3_assert(is_bv(a), "First argument must be a Z3 bit-vector expression")
4502 return BitVecRef(Z3_mk_bvredand(a.ctx_ref(), a.as_ast()), a.ctx)
4503
4504
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 4505 of file z3py.py.

4505def BVRedOr(a):
4506 """Return the reduction-or expression of `a`."""
4507 if z3_debug():
4508 _z3_assert(is_bv(a), "First argument must be a Z3 bit-vector expression")
4509 return BitVecRef(Z3_mk_bvredor(a.ctx_ref(), a.as_ast()), a.ctx)
4510
4511
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 4540 of file z3py.py.

4540def BVSDivNoOverflow(a, b):
4541 """A predicate the determines that bit-vector signed division does not overflow"""
4542 _check_bv_args(a, b)
4543 a, b = _coerce_exprs(a, b)
4544 return BoolRef(Z3_mk_bvsdiv_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4545
4546
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 4547 of file z3py.py.

4547def BVSNegNoOverflow(a):
4548 """A predicate the determines that bit-vector unary negation does not overflow"""
4549 if z3_debug():
4550 _z3_assert(is_bv(a), "First argument must be a Z3 bit-vector expression")
4551 return BoolRef(Z3_mk_bvneg_no_overflow(a.ctx_ref(), a.as_ast()), a.ctx)
4552
4553
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 4526 of file z3py.py.

4526def BVSubNoOverflow(a, b):
4527 """A predicate the determines that bit-vector subtraction does not overflow"""
4528 _check_bv_args(a, b)
4529 a, b = _coerce_exprs(a, b)
4530 return BoolRef(Z3_mk_bvsub_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4531
4532
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 4533 of file z3py.py.

4533def BVSubNoUnderflow(a, b, signed):
4534 """A predicate the determines that bit-vector subtraction does not underflow"""
4535 _check_bv_args(a, b)
4536 a, b = _coerce_exprs(a, b)
4537 return BoolRef(Z3_mk_bvsub_no_underflow(a.ctx_ref(), a.as_ast(), b.as_ast(), signed), a.ctx)
4538
4539
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 3477 of file z3py.py.

3477def Cbrt(a, ctx=None):
3478 """ Return a Z3 expression which represents the cubic root of a.
3479
3480 >>> x = Real('x')
3481 >>> Cbrt(x)
3482 x**(1/3)
3483 """
3484 if not is_expr(a):
3485 ctx = _get_ctx(ctx)
3486 a = RealVal(a, ctx)
3487 return a ** "1/3"
3488

◆ CharFromBv()

CharFromBv ( bv)

Definition at line 11036 of file z3py.py.

11036def CharFromBv(bv):
11037 if not is_expr(bv):
11038 raise Z3Exception("Bit-vector expression needed")
11039 return _to_expr_ref(Z3_mk_char_from_bv(bv.ctx_ref(), bv.as_ast()), bv.ctx)
11040
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 11049 of file z3py.py.

11049def CharIsDigit(ch, ctx=None):
11050 ch = _coerce_char(ch, ctx)
11051 return ch.is_digit()
11052

◆ CharSort()

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

Definition at line 10935 of file z3py.py.

10935def CharSort(ctx=None):
10936 """Create a character sort
10937 >>> ch = CharSort()
10938 >>> print(ch)
10939 Char
10940 """
10941 ctx = _get_ctx(ctx)
10942 return CharSortRef(Z3_mk_char_sort(ctx.ref()), ctx)
10943
10944
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 11041 of file z3py.py.

11041def CharToBv(ch, ctx=None):
11042 ch = _coerce_char(ch, ctx)
11043 return ch.to_bv()
11044

◆ CharToInt()

CharToInt ( ch,
ctx = None )

Definition at line 11045 of file z3py.py.

11045def CharToInt(ch, ctx=None):
11046 ch = _coerce_char(ch, ctx)
11047 return ch.to_int()
11048

◆ CharVal()

CharVal ( ch,
ctx = None )

Definition at line 11028 of file z3py.py.

11028def CharVal(ch, ctx=None):
11029 ctx = _get_ctx(ctx)
11030 if isinstance(ch, str):
11031 ch = ord(ch)
11032 if not isinstance(ch, int):
11033 raise Z3Exception("character value should be an ordinal")
11034 return _to_expr_ref(Z3_mk_char(ctx.ref(), ch), ctx)
11035
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 11460 of file z3py.py.

11460def Complement(re):
11461 """Create the complement regular expression."""
11462 return ReRef(Z3_mk_re_complement(re.ctx_ref(), re.as_ast()), re.ctx)
11463
11464
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 4135 of file z3py.py.

4135def Concat(*args):
4136 """Create a Z3 bit-vector concatenation expression.
4137
4138 >>> v = BitVecVal(1, 4)
4139 >>> Concat(v, v+1, v)
4140 Concat(Concat(1, 1 + 1), 1)
4141 >>> simplify(Concat(v, v+1, v))
4142 289
4143 >>> print("%.3x" % simplify(Concat(v, v+1, v)).as_long())
4144 121
4145 """
4146 args = _get_args(args)
4147 sz = len(args)
4148 if z3_debug():
4149 _z3_assert(sz >= 2, "At least two arguments expected.")
4150
4151 ctx = None
4152 for a in args:
4153 if is_expr(a):
4154 ctx = a.ctx
4155 break
4156 if is_seq(args[0]) or isinstance(args[0], str):
4157 args = [_coerce_seq(s, ctx) for s in args]
4158 if z3_debug():
4159 _z3_assert(all([is_seq(a) for a in args]), "All arguments must be sequence expressions.")
4160 v = (Ast * sz)()
4161 for i in range(sz):
4162 v[i] = args[i].as_ast()
4163 return SeqRef(Z3_mk_seq_concat(ctx.ref(), sz, v), ctx)
4164
4165 if is_re(args[0]):
4166 if z3_debug():
4167 _z3_assert(all([is_re(a) for a in args]), "All arguments must be regular expressions.")
4168 v = (Ast * sz)()
4169 for i in range(sz):
4170 v[i] = args[i].as_ast()
4171 return ReRef(Z3_mk_re_concat(ctx.ref(), sz, v), ctx)
4172
4173 if z3_debug():
4174 _z3_assert(all([is_bv(a) for a in args]), "All arguments must be Z3 bit-vector expressions.")
4175 r = args[0]
4176 for i in range(sz - 1):
4177 r = BitVecRef(Z3_mk_concat(ctx.ref(), r.as_ast(), args[i + 1].as_ast()), ctx)
4178 return r
4179
4180
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 8934 of file z3py.py.

8934def Cond(p, t1, t2, ctx=None):
8935 """Return a tactic that applies tactic `t1` to a goal if probe `p` evaluates to true, and `t2` otherwise.
8936
8937 >>> t = Cond(Probe('is-qfnra'), Tactic('qfnra'), Tactic('smt'))
8938 """
8939 p = _to_probe(p, ctx)
8940 t1 = _to_tactic(t1, ctx)
8941 t2 = _to_tactic(t2, ctx)
8942 return Tactic(Z3_tactic_cond(t1.ctx.ref(), p.probe, t1.tactic, t2.tactic), t1.ctx)
8943
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 1462 of file z3py.py.

1462def Const(name, sort):
1463 """Create a constant of the given sort.
1464
1465 >>> Const('x', IntSort())
1466 x
1467 """
1468 if z3_debug():
1469 _z3_assert(isinstance(sort, SortRef), "Z3 sort expected")
1470 ctx = sort.ctx
1471 return _to_expr_ref(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), sort.ast), ctx)
1472
1473

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

1474def Consts(names, sort):
1475 """Create several constants of the given sort.
1476
1477 `names` is a string containing the names of all constants to be created.
1478 Blank spaces separate the names of different constants.
1479
1480 >>> x, y, z = Consts('x y z', IntSort())
1481 >>> x + y + z
1482 x + y + z
1483 """
1484 if isinstance(names, str):
1485 names = names.split(" ")
1486 return [Const(name, sort) for name in names]
1487
1488

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

11205def Contains(a, b):
11206 """Check if 'a' contains 'b'
11207 >>> s1 = Contains("abc", "ab")
11208 >>> simplify(s1)
11209 True
11210 >>> s2 = Contains("abc", "bc")
11211 >>> simplify(s2)
11212 True
11213 >>> x, y, z = Strings('x y z')
11214 >>> s3 = Contains(Concat(x,y,z), y)
11215 >>> simplify(s3)
11216 True
11217 """
11218 ctx = _get_ctx2(a, b)
11219 a = _coerce_seq(a, ctx)
11220 b = _coerce_seq(b, ctx)
11221 return BoolRef(Z3_mk_seq_contains(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
11222
11223
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 5211 of file z3py.py.

5211def CreateDatatypes(*ds):
5212 """Create mutually recursive Z3 datatypes using 1 or more Datatype helper objects.
5213
5214 In the following example we define a Tree-List using two mutually recursive datatypes.
5215
5216 >>> TreeList = Datatype('TreeList')
5217 >>> Tree = Datatype('Tree')
5218 >>> # Tree has two constructors: leaf and node
5219 >>> Tree.declare('leaf', ('val', IntSort()))
5220 >>> # a node contains a list of trees
5221 >>> Tree.declare('node', ('children', TreeList))
5222 >>> TreeList.declare('nil')
5223 >>> TreeList.declare('cons', ('car', Tree), ('cdr', TreeList))
5224 >>> Tree, TreeList = CreateDatatypes(Tree, TreeList)
5225 >>> Tree.val(Tree.leaf(10))
5226 val(leaf(10))
5227 >>> simplify(Tree.val(Tree.leaf(10)))
5228 10
5229 >>> n1 = Tree.node(TreeList.cons(Tree.leaf(10), TreeList.cons(Tree.leaf(20), TreeList.nil)))
5230 >>> n1
5231 node(cons(leaf(10), cons(leaf(20), nil)))
5232 >>> n2 = Tree.node(TreeList.cons(n1, TreeList.nil))
5233 >>> simplify(n2 == n1)
5234 False
5235 >>> simplify(TreeList.car(Tree.children(n2)) == n1)
5236 True
5237 """
5238 ds = _get_args(ds)
5239 if z3_debug():
5240 _z3_assert(len(ds) > 0, "At least one Datatype must be specified")
5241 _z3_assert(all([isinstance(d, Datatype) for d in ds]), "Arguments must be Datatypes")
5242 _z3_assert(all([d.ctx == ds[0].ctx for d in ds]), "Context mismatch")
5243 _z3_assert(all([d.constructors != [] for d in ds]), "Non-empty Datatypes expected")
5244 ctx = ds[0].ctx
5245 num = len(ds)
5246 names = (Symbol * num)()
5247 out = (Sort * num)()
5248 clists = (ConstructorList * num)()
5249 to_delete = []
5250 for i in range(num):
5251 d = ds[i]
5252 names[i] = to_symbol(d.name, ctx)
5253 num_cs = len(d.constructors)
5254 cs = (Constructor * num_cs)()
5255 for j in range(num_cs):
5256 c = d.constructors[j]
5257 cname = to_symbol(c[0], ctx)
5258 rname = to_symbol(c[1], ctx)
5259 fs = c[2]
5260 num_fs = len(fs)
5261 fnames = (Symbol * num_fs)()
5262 sorts = (Sort * num_fs)()
5263 refs = (ctypes.c_uint * num_fs)()
5264 for k in range(num_fs):
5265 fname = fs[k][0]
5266 ftype = fs[k][1]
5267 fnames[k] = to_symbol(fname, ctx)
5268 if isinstance(ftype, Datatype):
5269 if z3_debug():
5270 _z3_assert(
5271 ds.count(ftype) == 1,
5272 "One and only one occurrence of each datatype is expected",
5273 )
5274 sorts[k] = None
5275 refs[k] = ds.index(ftype)
5276 else:
5277 if z3_debug():
5278 _z3_assert(is_sort(ftype), "Z3 sort expected")
5279 sorts[k] = ftype.ast
5280 refs[k] = 0
5281 cs[j] = Z3_mk_constructor(ctx.ref(), cname, rname, num_fs, fnames, sorts, refs)
5282 to_delete.append(ScopedConstructor(cs[j], ctx))
5283 clists[i] = Z3_mk_constructor_list(ctx.ref(), num_cs, cs)
5284 to_delete.append(ScopedConstructorList(clists[i], ctx))
5285 Z3_mk_datatypes(ctx.ref(), num, names, out, clists)
5286 result = []
5287 # Create a field for every constructor, recognizer and accessor
5288 for i in range(num):
5289 dref = DatatypeSortRef(out[i], ctx)
5290 num_cs = dref.num_constructors()
5291 for j in range(num_cs):
5292 cref = dref.constructor(j)
5293 cref_name = cref.name()
5294 cref_arity = cref.arity()
5295 if cref.arity() == 0:
5296 cref = cref()
5297 setattr(dref, cref_name, cref)
5298 rref = dref.recognizer(j)
5299 setattr(dref, "is_" + cref_name, rref)
5300 for k in range(cref_arity):
5301 aref = dref.accessor(j, k)
5302 setattr(dref, aref.name(), aref)
5303 result.append(dref)
5304 return tuple(result)
5305
5306
Z3_constructor Z3_API Z3_mk_constructor(Z3_context c, Z3_symbol name, Z3_symbol recognizer, unsigned num_fields, Z3_symbol const field_names[], Z3_sort_opt const sorts[], unsigned sort_refs[])
Create a constructor.
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.

Referenced by Datatype.create().

◆ DatatypeSort()

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

Definition at line 5411 of file z3py.py.

5411def DatatypeSort(name, ctx = None):
5412 """Create a reference to a sort that was declared, or will be declared, as a recursive datatype"""
5413 ctx = _get_ctx(ctx)
5414 return DatatypeSortRef(Z3_mk_datatype_sort(ctx.ref(), to_symbol(name, ctx)), ctx)
5415
Z3_sort Z3_API Z3_mk_datatype_sort(Z3_context c, Z3_symbol name)
create a forward reference to a recursive datatype being declared. The forward reference can be used ...

◆ DeclareSort()

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

695def DeclareSort(name, ctx=None):
696 """Create a new uninterpreted sort named `name`.
697
698 If `ctx=None`, then the new sort is declared in the global Z3Py context.
699
700 >>> A = DeclareSort('A')
701 >>> a = Const('a', A)
702 >>> b = Const('b', A)
703 >>> a.sort() == A
704 True
705 >>> b.sort() == A
706 True
707 >>> a == b
708 a == b
709 """
710 ctx = _get_ctx(ctx)
711 return SortRef(Z3_mk_uninterpreted_sort(ctx.ref(), to_symbol(name, ctx)), ctx)
712
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 723 of file z3py.py.

723def DeclareTypeVar(name, ctx=None):
724 """Create a new type variable named `name`.
725
726 If `ctx=None`, then the new sort is declared in the global Z3Py context.
727
728 """
729 ctx = _get_ctx(ctx)
730 return TypeVarRef(Z3_mk_type_variable(ctx.ref(), to_symbol(name, ctx)), ctx)
731
732
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 4832 of file z3py.py.

4832def Default(a):
4833 """ Return a default value for array expression.
4834 >>> b = K(IntSort(), 1)
4835 >>> prove(Default(b) == 1)
4836 proved
4837 """
4838 if z3_debug():
4839 _z3_assert(is_array_sort(a), "First argument must be a Z3 array expression")
4840 return a.default()
4841
4842

◆ describe_probes()

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

Definition at line 8855 of file z3py.py.

8855def describe_probes():
8856 """Display a (tabular) description of all available probes in Z3."""
8857 if in_html_mode():
8858 even = True
8859 print('<table border="1" cellpadding="2" cellspacing="0">')
8860 for p in probes():
8861 if even:
8862 print('<tr style="background-color:#CFCFCF">')
8863 even = False
8864 else:
8865 print("<tr>")
8866 even = True
8867 print("<td>%s</td><td>%s</td></tr>" % (p, insert_line_breaks(probe_description(p), 40)))
8868 print("</table>")
8869 else:
8870 for p in probes():
8871 print("%s : %s" % (p, probe_description(p)))
8872
8873

◆ describe_tactics()

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

Definition at line 8649 of file z3py.py.

8649def describe_tactics():
8650 """Display a (tabular) description of all available tactics in Z3."""
8651 if in_html_mode():
8652 even = True
8653 print('<table border="1" cellpadding="2" cellspacing="0">')
8654 for t in tactics():
8655 if even:
8656 print('<tr style="background-color:#CFCFCF">')
8657 even = False
8658 else:
8659 print("<tr>")
8660 even = True
8661 print("<td>%s</td><td>%s</td></tr>" % (t, insert_line_breaks(tactic_description(t), 40)))
8662 print("</table>")
8663 else:
8664 for t in tactics():
8665 print("%s : %s" % (t, tactic_description(t)))
8666
8667

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

1144def deserialize(st):
1145 """inverse function to the serialize method on ExprRef.
1146 It is made available to make it easier for users to serialize expressions back and forth between
1147 strings. Solvers can be serialized using the 'sexpr()' method.
1148 """
1149 s = Solver()
1150 s.from_string(st)
1151 if len(s.assertions()) != 1:
1152 raise Z3Exception("single assertion expected")
1153 fml = s.assertions()[0]
1154 if fml.num_args() != 1:
1155 raise Z3Exception("dummy function 'F' expected")
1156 return fml.arg(0)
1157

◆ Diff()

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

Definition at line 11510 of file z3py.py.

11510def Diff(a, b, ctx=None):
11511 """Create the difference regular expression
11512 """
11513 if z3_debug():
11514 _z3_assert(is_expr(a), "expression expected")
11515 _z3_assert(is_expr(b), "expression expected")
11516 return ReRef(Z3_mk_re_diff(a.ctx_ref(), a.ast, b.ast), a.ctx)
11517
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 79 of file z3py.py.

79def disable_trace(msg):
81
82
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 5428 of file z3py.py.

5428def DisjointSum(name, sorts, ctx=None):
5429 """Create a named tagged union sort base on a set of underlying sorts
5430 Example:
5431 >>> sum, ((inject0, extract0), (inject1, extract1)) = DisjointSum("+", [IntSort(), StringSort()])
5432 """
5433 sum = Datatype(name, ctx)
5434 for i in range(len(sorts)):
5435 sum.declare("inject%d" % i, ("project%d" % i, sorts[i]))
5436 sum = sum.create()
5437 return sum, [(sum.constructor(i), sum.accessor(i, 0)) for i in range(len(sorts))]
5438
5439

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

1429def Distinct(*args):
1430 """Create a Z3 distinct expression.
1431
1432 >>> x = Int('x')
1433 >>> y = Int('y')
1434 >>> Distinct(x, y)
1435 x != y
1436 >>> z = Int('z')
1437 >>> Distinct(x, y, z)
1438 Distinct(x, y, z)
1439 >>> simplify(Distinct(x, y, z))
1440 Distinct(x, y, z)
1441 >>> simplify(Distinct(x, y, z), blast_distinct=True)
1442 And(Not(x == y), Not(x == z), Not(y == z))
1443 """
1444 args = _get_args(args)
1445 ctx = _ctx_from_ast_arg_list(args)
1446 if z3_debug():
1447 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
1448 args = _coerce_expr_list(args, ctx)
1449 _args, sz = _to_ast_array(args)
1450 return BoolRef(Z3_mk_distinct(ctx.ref(), sz, _args), ctx)
1451
1452
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 11135 of file z3py.py.

11135def Empty(s):
11136 """Create the empty sequence of the given sort
11137 >>> e = Empty(StringSort())
11138 >>> e2 = StringVal("")
11139 >>> print(e.eq(e2))
11140 True
11141 >>> e3 = Empty(SeqSort(IntSort()))
11142 >>> print(e3)
11143 Empty(Seq(Int))
11144 >>> e4 = Empty(ReSort(SeqSort(IntSort())))
11145 >>> print(e4)
11146 Empty(ReSort(Seq(Int)))
11147 """
11148 if isinstance(s, SeqSortRef):
11149 return SeqRef(Z3_mk_seq_empty(s.ctx_ref(), s.ast), s.ctx)
11150 if isinstance(s, ReSortRef):
11151 return ReRef(Z3_mk_re_empty(s.ctx_ref(), s.ast), s.ctx)
11152 raise Z3Exception("Non-sequence, non-regular expression sort passed to Empty")
11153
11154
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 4975 of file z3py.py.

4975def EmptySet(s):
4976 """Create the empty set
4977 >>> EmptySet(IntSort())
4978 K(Int, False)
4979 """
4980 ctx = s.ctx
4981 return ArrayRef(Z3_mk_empty_set(ctx.ref(), s.ast), ctx)
4982
4983
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 75 of file z3py.py.

75def enable_trace(msg):
77
78
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 11629 of file z3py.py.

11629def ensure_prop_closures():
11630 global _prop_closures
11631 if _prop_closures is None:
11632 _prop_closures = PropClosures()
11633
11634

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

5440def EnumSort(name, values, ctx=None):
5441 """Return a new enumeration sort named `name` containing the given values.
5442
5443 The result is a pair (sort, list of constants).
5444 Example:
5445 >>> Color, (red, green, blue) = EnumSort('Color', ['red', 'green', 'blue'])
5446 """
5447 if z3_debug():
5448 _z3_assert(isinstance(name, str), "Name must be a string")
5449 _z3_assert(all([isinstance(v, str) for v in values]), "Enumeration sort values must be strings")
5450 _z3_assert(len(values) > 0, "At least one value expected")
5451 ctx = _get_ctx(ctx)
5452 num = len(values)
5453 _val_names = (Symbol * num)()
5454 for i in range(num):
5455 _val_names[i] = to_symbol(values[i], ctx)
5456 _values = (FuncDecl * num)()
5457 _testers = (FuncDecl * num)()
5458 name = to_symbol(name, ctx)
5459 S = DatatypeSortRef(Z3_mk_enumeration_sort(ctx.ref(), name, num, _val_names, _values, _testers), ctx)
5460 V = []
5461 for i in range(num):
5462 V.append(FuncDeclRef(_values[i], ctx))
5463 V = [a() for a in V]
5464 return S, V
5465
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()

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

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

Definition at line 472 of file z3py.py.

472def eq(a, b):
473 """Return `True` if `a` and `b` are structurally identical AST nodes.
474
475 >>> x = Int('x')
476 >>> y = Int('y')
477 >>> eq(x, y)
478 False
479 >>> eq(x + 1, x + 1)
480 True
481 >>> eq(x + 1, 1 + x)
482 False
483 >>> eq(simplify(x + 1), simplify(1 + x))
484 True
485 """
486 if z3_debug():
487 _z3_assert(is_ast(a) and is_ast(b), "Z3 ASTs expected")
488 return a.eq(b)
489
490

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

2297def Exists(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2298 """Create a Z3 exists formula.
2299
2300 The parameters `weight`, `qif`, `skid`, `patterns` and `no_patterns` are optional annotations.
2301
2302
2303 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2304 >>> x = Int('x')
2305 >>> y = Int('y')
2306 >>> q = Exists([x, y], f(x, y) >= x, skid="foo")
2307 >>> q
2308 Exists([x, y], f(x, y) >= x)
2309 >>> is_quantifier(q)
2310 True
2311 >>> r = Tactic('nnf')(q).as_expr()
2312 >>> is_quantifier(r)
2313 False
2314 """
2315 return _mk_quantifier(False, vs, body, weight, qid, skid, patterns, no_patterns)
2316
2317

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

4921def Ext(a, b):
4922 """Return extensionality index for one-dimensional arrays.
4923 >> a, b = Consts('a b', SetSort(IntSort()))
4924 >> Ext(a, b)
4925 Ext(a, b)
4926 """
4927 ctx = a.ctx
4928 if z3_debug():
4929 _z3_assert(is_array_sort(a) and (is_array(b) or b.is_lambda()), "arguments must be arrays")
4930 return _to_expr_ref(Z3_mk_array_ext(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
4931
4932
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.
Extract is overloaded to also work on sequence extraction.
The functions SubString and SubSeq are redirected to Extract.
For this case, the arguments are reinterpreted as:
    high - is a sequence (string)
    low  - is an offset
    a    - is the length to be extracted

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

Definition at line 4181 of file z3py.py.

4181def Extract(high, low, a):
4182 """Create a Z3 bit-vector extraction expression.
4183 Extract is overloaded to also work on sequence extraction.
4184 The functions SubString and SubSeq are redirected to Extract.
4185 For this case, the arguments are reinterpreted as:
4186 high - is a sequence (string)
4187 low - is an offset
4188 a - is the length to be extracted
4189
4190 >>> x = BitVec('x', 8)
4191 >>> Extract(6, 2, x)
4192 Extract(6, 2, x)
4193 >>> Extract(6, 2, x).sort()
4194 BitVec(5)
4195 >>> simplify(Extract(StringVal("abcd"),2,1))
4196 "c"
4197 """
4198 if isinstance(high, str):
4199 high = StringVal(high)
4200 if is_seq(high):
4201 s = high
4202 offset, length = _coerce_exprs(low, a, s.ctx)
4203 return SeqRef(Z3_mk_seq_extract(s.ctx_ref(), s.as_ast(), offset.as_ast(), length.as_ast()), s.ctx)
4204 if z3_debug():
4205 _z3_assert(low <= high, "First argument must be greater than or equal to second argument")
4206 _z3_assert(_is_int(high) and high >= 0 and _is_int(low) and low >= 0,
4207 "First and second arguments must be non negative integers")
4208 _z3_assert(is_bv(a), "Third argument must be a Z3 bit-vector expression")
4209 return BitVecRef(Z3_mk_extract(a.ctx_ref(), high, low, a.as_ast()), a.ctx)
4210
4211
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 8892 of file z3py.py.

8892def FailIf(p, ctx=None):
8893 """Return a tactic that fails if the probe `p` evaluates to true.
8894 Otherwise, it returns the input goal unmodified.
8895
8896 In the following example, the tactic applies 'simplify' if and only if there are
8897 more than 2 constraints in the goal.
8898
8899 >>> t = OrElse(FailIf(Probe('size') > 2), Tactic('simplify'))
8900 >>> x, y = Ints('x y')
8901 >>> g = Goal()
8902 >>> g.add(x > 0)
8903 >>> g.add(y > 0)
8904 >>> t(g)
8905 [[x > 0, y > 0]]
8906 >>> g.add(x == y + 1)
8907 >>> t(g)
8908 [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
8909 """
8910 p = _to_probe(p, ctx)
8911 return Tactic(Z3_tactic_fail_if(p.ctx.ref(), p.probe), p.ctx)
8912
8913
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 7823 of file z3py.py.

7823def FiniteDomainSort(name, sz, ctx=None):
7824 """Create a named finite domain sort of a given size sz"""
7825 if not isinstance(name, Symbol):
7826 name = to_symbol(name)
7827 ctx = _get_ctx(ctx)
7828 return FiniteDomainSortRef(Z3_mk_finite_domain_sort(ctx.ref(), name, sz), ctx)
7829
7830
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 7893 of file z3py.py.

7893def FiniteDomainVal(val, sort, ctx=None):
7894 """Return a Z3 finite-domain value. If `ctx=None`, then the global context is used.
7895
7896 >>> s = FiniteDomainSort('S', 256)
7897 >>> FiniteDomainVal(255, s)
7898 255
7899 >>> FiniteDomainVal('100', s)
7900 100
7901 """
7902 if z3_debug():
7903 _z3_assert(is_finite_domain_sort(sort), "Expected finite-domain sort")
7904 ctx = sort.ctx
7905 return FiniteDomainNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), sort.ast), ctx)
7906
7907

◆ Float128()

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

Definition at line 9620 of file z3py.py.

9620def Float128(ctx=None):
9621 """Floating-point 128-bit (quadruple) sort."""
9622 ctx = _get_ctx(ctx)
9623 return FPSortRef(Z3_mk_fpa_sort_128(ctx.ref()), ctx)
9624
9625
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 9584 of file z3py.py.

9584def Float16(ctx=None):
9585 """Floating-point 16-bit (half) sort."""
9586 ctx = _get_ctx(ctx)
9587 return FPSortRef(Z3_mk_fpa_sort_16(ctx.ref()), ctx)
9588
9589
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 9596 of file z3py.py.

9596def Float32(ctx=None):
9597 """Floating-point 32-bit (single) sort."""
9598 ctx = _get_ctx(ctx)
9599 return FPSortRef(Z3_mk_fpa_sort_32(ctx.ref()), ctx)
9600
9601
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 9608 of file z3py.py.

9608def Float64(ctx=None):
9609 """Floating-point 64-bit (double) sort."""
9610 ctx = _get_ctx(ctx)
9611 return FPSortRef(Z3_mk_fpa_sort_64(ctx.ref()), ctx)
9612
9613
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 9614 of file z3py.py.

9614def FloatDouble(ctx=None):
9615 """Floating-point 64-bit (double) sort."""
9616 ctx = _get_ctx(ctx)
9617 return FPSortRef(Z3_mk_fpa_sort_double(ctx.ref()), ctx)
9618
9619
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 9590 of file z3py.py.

9590def FloatHalf(ctx=None):
9591 """Floating-point 16-bit (half) sort."""
9592 ctx = _get_ctx(ctx)
9593 return FPSortRef(Z3_mk_fpa_sort_half(ctx.ref()), ctx)
9594
9595
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 9626 of file z3py.py.

9626def FloatQuadruple(ctx=None):
9627 """Floating-point 128-bit (quadruple) sort."""
9628 ctx = _get_ctx(ctx)
9629 return FPSortRef(Z3_mk_fpa_sort_quadruple(ctx.ref()), ctx)
9630
9631
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 9602 of file z3py.py.

9602def FloatSingle(ctx=None):
9603 """Floating-point 32-bit (single) sort."""
9604 ctx = _get_ctx(ctx)
9605 return FPSortRef(Z3_mk_fpa_sort_single(ctx.ref()), ctx)
9606
9607
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 2279 of file z3py.py.

2279def ForAll(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2280 """Create a Z3 forall formula.
2281
2282 The parameters `weight`, `qid`, `skid`, `patterns` and `no_patterns` are optional annotations.
2283
2284 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2285 >>> x = Int('x')
2286 >>> y = Int('y')
2287 >>> ForAll([x, y], f(x, y) >= x)
2288 ForAll([x, y], f(x, y) >= x)
2289 >>> ForAll([x, y], f(x, y) >= x, patterns=[ f(x, y) ])
2290 ForAll([x, y], f(x, y) >= x)
2291 >>> ForAll([x, y], f(x, y) >= x, weight=10)
2292 ForAll([x, y], f(x, y) >= x)
2293 """
2294 return _mk_quantifier(True, vs, body, weight, qid, skid, patterns, no_patterns)
2295
2296

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

10252def FP(name, fpsort, ctx=None):
10253 """Return a floating-point constant named `name`.
10254 `fpsort` is the floating-point sort.
10255 If `ctx=None`, then the global context is used.
10256
10257 >>> x = FP('x', FPSort(8, 24))
10258 >>> is_fp(x)
10259 True
10260 >>> x.ebits()
10261 8
10262 >>> x.sort()
10263 FPSort(8, 24)
10264 >>> word = FPSort(8, 24)
10265 >>> x2 = FP('x', word)
10266 >>> eq(x, x2)
10267 True
10268 """
10269 if isinstance(fpsort, FPSortRef) and ctx is None:
10270 ctx = fpsort.ctx
10271 else:
10272 ctx = _get_ctx(ctx)
10273 return FPRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), fpsort.ast), ctx)
10274
10275

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

10295def fpAbs(a, ctx=None):
10296 """Create a Z3 floating-point absolute value expression.
10297
10298 >>> s = FPSort(8, 24)
10299 >>> rm = RNE()
10300 >>> x = FPVal(1.0, s)
10301 >>> fpAbs(x)
10302 fpAbs(1)
10303 >>> y = FPVal(-20.0, s)
10304 >>> y
10305 -1.25*(2**4)
10306 >>> fpAbs(y)
10307 fpAbs(-1.25*(2**4))
10308 >>> fpAbs(-1.25*(2**4))
10309 fpAbs(-1.25*(2**4))
10310 >>> fpAbs(x).sort()
10311 FPSort(8, 24)
10312 """
10313 ctx = _get_ctx(ctx)
10314 [a] = _coerce_fp_expr_list([a], ctx)
10315 return FPRef(Z3_mk_fpa_abs(ctx.ref(), a.as_ast()), ctx)
10316
10317
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 10386 of file z3py.py.

10386def fpAdd(rm, a, b, ctx=None):
10387 """Create a Z3 floating-point addition expression.
10388
10389 >>> s = FPSort(8, 24)
10390 >>> rm = RNE()
10391 >>> x = FP('x', s)
10392 >>> y = FP('y', s)
10393 >>> fpAdd(rm, x, y)
10394 x + y
10395 >>> fpAdd(RTZ(), x, y) # default rounding mode is RTZ
10396 fpAdd(RTZ(), x, y)
10397 >>> fpAdd(rm, x, y).sort()
10398 FPSort(8, 24)
10399 """
10400 return _mk_fp_bin(Z3_mk_fpa_add, rm, a, b, ctx)
10401
10402

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

10708def fpBVToFP(v, sort, ctx=None):
10709 """Create a Z3 floating-point conversion expression that represents the
10710 conversion from a bit-vector term to a floating-point term.
10711
10712 >>> x_bv = BitVecVal(0x3F800000, 32)
10713 >>> x_fp = fpBVToFP(x_bv, Float32())
10714 >>> x_fp
10715 fpToFP(1065353216)
10716 >>> simplify(x_fp)
10717 1
10718 """
10719 _z3_assert(is_bv(v), "First argument must be a Z3 bit-vector expression")
10720 _z3_assert(is_fp_sort(sort), "Second argument must be a Z3 floating-point sort.")
10721 ctx = _get_ctx(ctx)
10722 return FPRef(Z3_mk_fpa_to_fp_bv(ctx.ref(), v.ast, sort.ast), ctx)
10723
10724
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 10433 of file z3py.py.

10433def fpDiv(rm, a, b, ctx=None):
10434 """Create a Z3 floating-point division expression.
10435
10436 >>> s = FPSort(8, 24)
10437 >>> rm = RNE()
10438 >>> x = FP('x', s)
10439 >>> y = FP('y', s)
10440 >>> fpDiv(rm, x, y)
10441 x / y
10442 >>> fpDiv(rm, x, y).sort()
10443 FPSort(8, 24)
10444 """
10445 return _mk_fp_bin(Z3_mk_fpa_div, rm, a, b, ctx)
10446
10447

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

10616def fpEQ(a, b, ctx=None):
10617 """Create the Z3 floating-point expression `fpEQ(other, self)`.
10618
10619 >>> x, y = FPs('x y', FPSort(8, 24))
10620 >>> fpEQ(x, y)
10621 fpEQ(x, y)
10622 >>> fpEQ(x, y).sexpr()
10623 '(fp.eq x y)'
10624 """
10625 return _mk_fp_bin_pred(Z3_mk_fpa_eq, a, b, ctx)
10626
10627

◆ fpFMA()

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

Definition at line 10492 of file z3py.py.

10492def fpFMA(rm, a, b, c, ctx=None):
10493 """Create a Z3 floating-point fused multiply-add expression.
10494 """
10495 return _mk_fp_tern(Z3_mk_fpa_fma, rm, a, b, c, ctx)
10496
10497

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

10640def fpFP(sgn, exp, sig, ctx=None):
10641 """Create the Z3 floating-point value `fpFP(sgn, sig, exp)` from the three bit-vectors sgn, sig, and exp.
10642
10643 >>> s = FPSort(8, 24)
10644 >>> x = fpFP(BitVecVal(1, 1), BitVecVal(2**7-1, 8), BitVecVal(2**22, 23))
10645 >>> print(x)
10646 fpFP(1, 127, 4194304)
10647 >>> xv = FPVal(-1.5, s)
10648 >>> print(xv)
10649 -1.5
10650 >>> slvr = Solver()
10651 >>> slvr.add(fpEQ(x, xv))
10652 >>> slvr.check()
10653 sat
10654 >>> xv = FPVal(+1.5, s)
10655 >>> print(xv)
10656 1.5
10657 >>> slvr = Solver()
10658 >>> slvr.add(fpEQ(x, xv))
10659 >>> slvr.check()
10660 unsat
10661 """
10662 _z3_assert(is_bv(sgn) and is_bv(exp) and is_bv(sig), "sort mismatch")
10663 _z3_assert(sgn.sort().size() == 1, "sort mismatch")
10664 ctx = _get_ctx(ctx)
10665 _z3_assert(ctx == sgn.ctx == exp.ctx == sig.ctx, "context mismatch")
10666 return FPRef(Z3_mk_fpa_fp(ctx.ref(), sgn.ast, exp.ast, sig.ast), ctx)
10667
10668
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 10725 of file z3py.py.

10725def fpFPToFP(rm, v, sort, ctx=None):
10726 """Create a Z3 floating-point conversion expression that represents the
10727 conversion from a floating-point term to a floating-point term of different precision.
10728
10729 >>> x_sgl = FPVal(1.0, Float32())
10730 >>> x_dbl = fpFPToFP(RNE(), x_sgl, Float64())
10731 >>> x_dbl
10732 fpToFP(RNE(), 1)
10733 >>> simplify(x_dbl)
10734 1
10735 >>> x_dbl.sort()
10736 FPSort(11, 53)
10737 """
10738 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10739 _z3_assert(is_fp(v), "Second argument must be a Z3 floating-point expression.")
10740 _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
10741 ctx = _get_ctx(ctx)
10742 return FPRef(Z3_mk_fpa_to_fp_float(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
10743
10744
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 10604 of file z3py.py.

10604def fpGEQ(a, b, ctx=None):
10605 """Create the Z3 floating-point expression `other >= self`.
10606
10607 >>> x, y = FPs('x y', FPSort(8, 24))
10608 >>> fpGEQ(x, y)
10609 x >= y
10610 >>> (x >= y).sexpr()
10611 '(fp.geq x y)'
10612 """
10613 return _mk_fp_bin_pred(Z3_mk_fpa_geq, a, b, ctx)
10614
10615

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

10592def fpGT(a, b, ctx=None):
10593 """Create the Z3 floating-point expression `other > self`.
10594
10595 >>> x, y = FPs('x y', FPSort(8, 24))
10596 >>> fpGT(x, y)
10597 x > y
10598 >>> (x > y).sexpr()
10599 '(fp.gt x y)'
10600 """
10601 return _mk_fp_bin_pred(Z3_mk_fpa_gt, a, b, ctx)
10602
10603

◆ fpInfinity()

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

Definition at line 10180 of file z3py.py.

10180def fpInfinity(s, negative):
10181 """Create a Z3 floating-point +oo or -oo term."""
10182 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10183 _z3_assert(isinstance(negative, bool), "expected Boolean flag")
10184 return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, negative), s.ctx)
10185
10186
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 10522 of file z3py.py.

10522def fpIsInf(a, ctx=None):
10523 """Create a Z3 floating-point isInfinite expression.
10524
10525 >>> s = FPSort(8, 24)
10526 >>> x = FP('x', s)
10527 >>> fpIsInf(x)
10528 fpIsInf(x)
10529 """
10530 return _mk_fp_unary_pred(Z3_mk_fpa_is_infinite, a, ctx)
10531
10532

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

10510def fpIsNaN(a, ctx=None):
10511 """Create a Z3 floating-point isNaN expression.
10512
10513 >>> s = FPSort(8, 24)
10514 >>> x = FP('x', s)
10515 >>> y = FP('y', s)
10516 >>> fpIsNaN(x)
10517 fpIsNaN(x)
10518 """
10519 return _mk_fp_unary_pred(Z3_mk_fpa_is_nan, a, ctx)
10520
10521

◆ fpIsNegative()

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

Definition at line 10551 of file z3py.py.

10551def fpIsNegative(a, ctx=None):
10552 """Create a Z3 floating-point isNegative expression.
10553 """
10554 return _mk_fp_unary_pred(Z3_mk_fpa_is_negative, a, ctx)
10555
10556

◆ fpIsNormal()

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

Definition at line 10539 of file z3py.py.

10539def fpIsNormal(a, ctx=None):
10540 """Create a Z3 floating-point isNormal expression.
10541 """
10542 return _mk_fp_unary_pred(Z3_mk_fpa_is_normal, a, ctx)
10543
10544

◆ fpIsPositive()

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

Definition at line 10557 of file z3py.py.

10557def fpIsPositive(a, ctx=None):
10558 """Create a Z3 floating-point isPositive expression.
10559 """
10560 return _mk_fp_unary_pred(Z3_mk_fpa_is_positive, a, ctx)
10561
10562

◆ fpIsSubnormal()

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

Definition at line 10545 of file z3py.py.

10545def fpIsSubnormal(a, ctx=None):
10546 """Create a Z3 floating-point isSubnormal expression.
10547 """
10548 return _mk_fp_unary_pred(Z3_mk_fpa_is_subnormal, a, ctx)
10549
10550

◆ fpIsZero()

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

Definition at line 10533 of file z3py.py.

10533def fpIsZero(a, ctx=None):
10534 """Create a Z3 floating-point isZero expression.
10535 """
10536 return _mk_fp_unary_pred(Z3_mk_fpa_is_zero, a, ctx)
10537
10538

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

10580def fpLEQ(a, b, ctx=None):
10581 """Create the Z3 floating-point expression `other <= self`.
10582
10583 >>> x, y = FPs('x y', FPSort(8, 24))
10584 >>> fpLEQ(x, y)
10585 x <= y
10586 >>> (x <= y).sexpr()
10587 '(fp.leq x y)'
10588 """
10589 return _mk_fp_bin_pred(Z3_mk_fpa_leq, a, b, ctx)
10590
10591

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

10568def fpLT(a, b, ctx=None):
10569 """Create the Z3 floating-point expression `other < self`.
10570
10571 >>> x, y = FPs('x y', FPSort(8, 24))
10572 >>> fpLT(x, y)
10573 x < y
10574 >>> (x < y).sexpr()
10575 '(fp.lt x y)'
10576 """
10577 return _mk_fp_bin_pred(Z3_mk_fpa_lt, a, b, ctx)
10578
10579

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

10477def fpMax(a, b, ctx=None):
10478 """Create a Z3 floating-point maximum expression.
10479
10480 >>> s = FPSort(8, 24)
10481 >>> rm = RNE()
10482 >>> x = FP('x', s)
10483 >>> y = FP('y', s)
10484 >>> fpMax(x, y)
10485 fpMax(x, y)
10486 >>> fpMax(x, y).sort()
10487 FPSort(8, 24)
10488 """
10489 return _mk_fp_bin_norm(Z3_mk_fpa_max, a, b, ctx)
10490
10491

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

10462def fpMin(a, b, ctx=None):
10463 """Create a Z3 floating-point minimum expression.
10464
10465 >>> s = FPSort(8, 24)
10466 >>> rm = RNE()
10467 >>> x = FP('x', s)
10468 >>> y = FP('y', s)
10469 >>> fpMin(x, y)
10470 fpMin(x, y)
10471 >>> fpMin(x, y).sort()
10472 FPSort(8, 24)
10473 """
10474 return _mk_fp_bin_norm(Z3_mk_fpa_min, a, b, ctx)
10475
10476

◆ fpMinusInfinity()

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

Definition at line 10174 of file z3py.py.

10174def fpMinusInfinity(s):
10175 """Create a Z3 floating-point -oo term."""
10176 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10177 return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, True), s.ctx)
10178
10179

◆ fpMinusZero()

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

Definition at line 10193 of file z3py.py.

10193def fpMinusZero(s):
10194 """Create a Z3 floating-point -0.0 term."""
10195 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10196 return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, True), s.ctx)
10197
10198
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 10418 of file z3py.py.

10418def fpMul(rm, a, b, ctx=None):
10419 """Create a Z3 floating-point multiplication expression.
10420
10421 >>> s = FPSort(8, 24)
10422 >>> rm = RNE()
10423 >>> x = FP('x', s)
10424 >>> y = FP('y', s)
10425 >>> fpMul(rm, x, y)
10426 x * y
10427 >>> fpMul(rm, x, y).sort()
10428 FPSort(8, 24)
10429 """
10430 return _mk_fp_bin(Z3_mk_fpa_mul, rm, a, b, ctx)
10431
10432

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

10140def fpNaN(s):
10141 """Create a Z3 floating-point NaN term.
10142
10143 >>> s = FPSort(8, 24)
10144 >>> set_fpa_pretty(True)
10145 >>> fpNaN(s)
10146 NaN
10147 >>> pb = get_fpa_pretty()
10148 >>> set_fpa_pretty(False)
10149 >>> fpNaN(s)
10150 fpNaN(FPSort(8, 24))
10151 >>> set_fpa_pretty(pb)
10152 """
10153 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10154 return FPNumRef(Z3_mk_fpa_nan(s.ctx_ref(), s.ast), s.ctx)
10155
10156
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 10318 of file z3py.py.

10318def fpNeg(a, ctx=None):
10319 """Create a Z3 floating-point addition expression.
10320
10321 >>> s = FPSort(8, 24)
10322 >>> rm = RNE()
10323 >>> x = FP('x', s)
10324 >>> fpNeg(x)
10325 -x
10326 >>> fpNeg(x).sort()
10327 FPSort(8, 24)
10328 """
10329 ctx = _get_ctx(ctx)
10330 [a] = _coerce_fp_expr_list([a], ctx)
10331 return FPRef(Z3_mk_fpa_neg(ctx.ref(), a.as_ast()), ctx)
10332
10333
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 10628 of file z3py.py.

10628def fpNEQ(a, b, ctx=None):
10629 """Create the Z3 floating-point expression `Not(fpEQ(other, self))`.
10630
10631 >>> x, y = FPs('x y', FPSort(8, 24))
10632 >>> fpNEQ(x, y)
10633 Not(fpEQ(x, y))
10634 >>> (x != y).sexpr()
10635 '(distinct x y)'
10636 """
10637 return Not(fpEQ(a, b, ctx))
10638
10639

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

10157def fpPlusInfinity(s):
10158 """Create a Z3 floating-point +oo term.
10159
10160 >>> s = FPSort(8, 24)
10161 >>> pb = get_fpa_pretty()
10162 >>> set_fpa_pretty(True)
10163 >>> fpPlusInfinity(s)
10164 +oo
10165 >>> set_fpa_pretty(False)
10166 >>> fpPlusInfinity(s)
10167 fpPlusInfinity(FPSort(8, 24))
10168 >>> set_fpa_pretty(pb)
10169 """
10170 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10171 return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, False), s.ctx)
10172
10173

◆ fpPlusZero()

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

Definition at line 10187 of file z3py.py.

10187def fpPlusZero(s):
10188 """Create a Z3 floating-point +0.0 term."""
10189 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10190 return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, False), s.ctx)
10191
10192

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

10745def fpRealToFP(rm, v, sort, ctx=None):
10746 """Create a Z3 floating-point conversion expression that represents the
10747 conversion from a real term to a floating-point term.
10748
10749 >>> x_r = RealVal(1.5)
10750 >>> x_fp = fpRealToFP(RNE(), x_r, Float32())
10751 >>> x_fp
10752 fpToFP(RNE(), 3/2)
10753 >>> simplify(x_fp)
10754 1.5
10755 """
10756 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10757 _z3_assert(is_real(v), "Second argument must be a Z3 expression or real sort.")
10758 _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
10759 ctx = _get_ctx(ctx)
10760 return FPRef(Z3_mk_fpa_to_fp_real(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
10761
10762
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 10448 of file z3py.py.

10448def fpRem(a, b, ctx=None):
10449 """Create a Z3 floating-point remainder expression.
10450
10451 >>> s = FPSort(8, 24)
10452 >>> x = FP('x', s)
10453 >>> y = FP('y', s)
10454 >>> fpRem(x, y)
10455 fpRem(x, y)
10456 >>> fpRem(x, y).sort()
10457 FPSort(8, 24)
10458 """
10459 return _mk_fp_bin_norm(Z3_mk_fpa_rem, a, b, ctx)
10460
10461

◆ fpRoundToIntegral()

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

Definition at line 10504 of file z3py.py.

10504def fpRoundToIntegral(rm, a, ctx=None):
10505 """Create a Z3 floating-point roundToIntegral expression.
10506 """
10507 return _mk_fp_unary(Z3_mk_fpa_round_to_integral, rm, a, ctx)
10508
10509

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

10276def FPs(names, fpsort, ctx=None):
10277 """Return an array of floating-point constants.
10278
10279 >>> x, y, z = FPs('x y z', FPSort(8, 24))
10280 >>> x.sort()
10281 FPSort(8, 24)
10282 >>> x.sbits()
10283 24
10284 >>> x.ebits()
10285 8
10286 >>> fpMul(RNE(), fpAdd(RNE(), x, y), z)
10287 (x + y) * z
10288 """
10289 ctx = _get_ctx(ctx)
10290 if isinstance(names, str):
10291 names = names.split(" ")
10292 return [FP(name, fpsort, ctx) for name in names]
10293
10294

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

10763def fpSignedToFP(rm, v, sort, ctx=None):
10764 """Create a Z3 floating-point conversion expression that represents the
10765 conversion from a signed bit-vector term (encoding an integer) to a floating-point term.
10766
10767 >>> x_signed = BitVecVal(-5, BitVecSort(32))
10768 >>> x_fp = fpSignedToFP(RNE(), x_signed, Float32())
10769 >>> x_fp
10770 fpToFP(RNE(), 4294967291)
10771 >>> simplify(x_fp)
10772 -1.25*(2**2)
10773 """
10774 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10775 _z3_assert(is_bv(v), "Second argument must be a Z3 bit-vector expression")
10776 _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
10777 ctx = _get_ctx(ctx)
10778 return FPRef(Z3_mk_fpa_to_fp_signed(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
10779
10780
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 10081 of file z3py.py.

10081def FPSort(ebits, sbits, ctx=None):
10082 """Return a Z3 floating-point sort of the given sizes. If `ctx=None`, then the global context is used.
10083
10084 >>> Single = FPSort(8, 24)
10085 >>> Double = FPSort(11, 53)
10086 >>> Single
10087 FPSort(8, 24)
10088 >>> x = Const('x', Single)
10089 >>> eq(x, FP('x', FPSort(8, 24)))
10090 True
10091 """
10092 ctx = _get_ctx(ctx)
10093 return FPSortRef(Z3_mk_fpa_sort(ctx.ref(), ebits, sbits), ctx)
10094
10095
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 10498 of file z3py.py.

10498def fpSqrt(rm, a, ctx=None):
10499 """Create a Z3 floating-point square root expression.
10500 """
10501 return _mk_fp_unary(Z3_mk_fpa_sqrt, rm, a, ctx)
10502
10503

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

10403def fpSub(rm, a, b, ctx=None):
10404 """Create a Z3 floating-point subtraction expression.
10405
10406 >>> s = FPSort(8, 24)
10407 >>> rm = RNE()
10408 >>> x = FP('x', s)
10409 >>> y = FP('y', s)
10410 >>> fpSub(rm, x, y)
10411 x - y
10412 >>> fpSub(rm, x, y).sort()
10413 FPSort(8, 24)
10414 """
10415 return _mk_fp_bin(Z3_mk_fpa_sub, rm, a, b, ctx)
10416
10417

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

10669def fpToFP(a1, a2=None, a3=None, ctx=None):
10670 """Create a Z3 floating-point conversion expression from other term sorts
10671 to floating-point.
10672
10673 From a bit-vector term in IEEE 754-2008 format:
10674 >>> x = FPVal(1.0, Float32())
10675 >>> x_bv = fpToIEEEBV(x)
10676 >>> simplify(fpToFP(x_bv, Float32()))
10677 1
10678
10679 From a floating-point term with different precision:
10680 >>> x = FPVal(1.0, Float32())
10681 >>> x_db = fpToFP(RNE(), x, Float64())
10682 >>> x_db.sort()
10683 FPSort(11, 53)
10684
10685 From a real term:
10686 >>> x_r = RealVal(1.5)
10687 >>> simplify(fpToFP(RNE(), x_r, Float32()))
10688 1.5
10689
10690 From a signed bit-vector term:
10691 >>> x_signed = BitVecVal(-5, BitVecSort(32))
10692 >>> simplify(fpToFP(RNE(), x_signed, Float32()))
10693 -1.25*(2**2)
10694 """
10695 ctx = _get_ctx(ctx)
10696 if is_bv(a1) and is_fp_sort(a2):
10697 return FPRef(Z3_mk_fpa_to_fp_bv(ctx.ref(), a1.ast, a2.ast), ctx)
10698 elif is_fprm(a1) and is_fp(a2) and is_fp_sort(a3):
10699 return FPRef(Z3_mk_fpa_to_fp_float(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
10700 elif is_fprm(a1) and is_real(a2) and is_fp_sort(a3):
10701 return FPRef(Z3_mk_fpa_to_fp_real(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
10702 elif is_fprm(a1) and is_bv(a2) and is_fp_sort(a3):
10703 return FPRef(Z3_mk_fpa_to_fp_signed(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
10704 else:
10705 raise Z3Exception("Unsupported combination of arguments for conversion to floating-point term.")
10706
10707

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

10799def fpToFPUnsigned(rm, x, s, ctx=None):
10800 """Create a Z3 floating-point conversion expression, from unsigned bit-vector to floating-point expression."""
10801 if z3_debug():
10802 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
10803 _z3_assert(is_bv(x), "Second argument must be a Z3 bit-vector expression")
10804 _z3_assert(is_fp_sort(s), "Third argument must be Z3 floating-point sort")
10805 ctx = _get_ctx(ctx)
10806 return FPRef(Z3_mk_fpa_to_fp_unsigned(ctx.ref(), rm.ast, x.ast, s.ast), ctx)
10807
10808
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 10873 of file z3py.py.

10873def fpToIEEEBV(x, ctx=None):
10874 """\brief Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.
10875
10876 The size of the resulting bit-vector is automatically determined.
10877
10878 Note that IEEE 754-2008 allows multiple different representations of NaN. This conversion
10879 knows only one NaN and it will always produce the same bit-vector representation of
10880 that NaN.
10881
10882 >>> x = FP('x', FPSort(8, 24))
10883 >>> y = fpToIEEEBV(x)
10884 >>> print(is_fp(x))
10885 True
10886 >>> print(is_bv(y))
10887 True
10888 >>> print(is_fp(y))
10889 False
10890 >>> print(is_bv(x))
10891 False
10892 """
10893 if z3_debug():
10894 _z3_assert(is_fp(x), "First argument must be a Z3 floating-point expression")
10895 ctx = _get_ctx(ctx)
10896 return BitVecRef(Z3_mk_fpa_to_ieee_bv(ctx.ref(), x.ast), ctx)
10897
10898
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 10853 of file z3py.py.

10853def fpToReal(x, ctx=None):
10854 """Create a Z3 floating-point conversion expression, from floating-point expression to real.
10855
10856 >>> x = FP('x', FPSort(8, 24))
10857 >>> y = fpToReal(x)
10858 >>> print(is_fp(x))
10859 True
10860 >>> print(is_real(y))
10861 True
10862 >>> print(is_fp(y))
10863 False
10864 >>> print(is_real(x))
10865 False
10866 """
10867 if z3_debug():
10868 _z3_assert(is_fp(x), "First argument must be a Z3 floating-point expression")
10869 ctx = _get_ctx(ctx)
10870 return ArithRef(Z3_mk_fpa_to_real(ctx.ref(), x.ast), ctx)
10871
10872
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 10809 of file z3py.py.

10809def fpToSBV(rm, x, s, ctx=None):
10810 """Create a Z3 floating-point conversion expression, from floating-point expression to signed bit-vector.
10811
10812 >>> x = FP('x', FPSort(8, 24))
10813 >>> y = fpToSBV(RTZ(), x, BitVecSort(32))
10814 >>> print(is_fp(x))
10815 True
10816 >>> print(is_bv(y))
10817 True
10818 >>> print(is_fp(y))
10819 False
10820 >>> print(is_bv(x))
10821 False
10822 """
10823 if z3_debug():
10824 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
10825 _z3_assert(is_fp(x), "Second argument must be a Z3 floating-point expression")
10826 _z3_assert(is_bv_sort(s), "Third argument must be Z3 bit-vector sort")
10827 ctx = _get_ctx(ctx)
10828 return BitVecRef(Z3_mk_fpa_to_sbv(ctx.ref(), rm.ast, x.ast, s.size()), ctx)
10829
10830
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 10831 of file z3py.py.

10831def fpToUBV(rm, x, s, ctx=None):
10832 """Create a Z3 floating-point conversion expression, from floating-point expression to unsigned bit-vector.
10833
10834 >>> x = FP('x', FPSort(8, 24))
10835 >>> y = fpToUBV(RTZ(), x, BitVecSort(32))
10836 >>> print(is_fp(x))
10837 True
10838 >>> print(is_bv(y))
10839 True
10840 >>> print(is_fp(y))
10841 False
10842 >>> print(is_bv(x))
10843 False
10844 """
10845 if z3_debug():
10846 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
10847 _z3_assert(is_fp(x), "Second argument must be a Z3 floating-point expression")
10848 _z3_assert(is_bv_sort(s), "Third argument must be Z3 bit-vector sort")
10849 ctx = _get_ctx(ctx)
10850 return BitVecRef(Z3_mk_fpa_to_ubv(ctx.ref(), rm.ast, x.ast, s.size()), ctx)
10851
10852
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 10781 of file z3py.py.

10781def fpUnsignedToFP(rm, v, sort, ctx=None):
10782 """Create a Z3 floating-point conversion expression that represents the
10783 conversion from an unsigned bit-vector term (encoding an integer) to a floating-point term.
10784
10785 >>> x_signed = BitVecVal(-5, BitVecSort(32))
10786 >>> x_fp = fpUnsignedToFP(RNE(), x_signed, Float32())
10787 >>> x_fp
10788 fpToFPUnsigned(RNE(), 4294967291)
10789 >>> simplify(x_fp)
10790 1*(2**32)
10791 """
10792 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10793 _z3_assert(is_bv(v), "Second argument must be a Z3 bit-vector expression")
10794 _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
10795 ctx = _get_ctx(ctx)
10796 return FPRef(Z3_mk_fpa_to_fp_unsigned(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
10797
10798

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

10206def FPVal(sig, exp=None, fps=None, ctx=None):
10207 """Return a floating-point value of value `val` and sort `fps`.
10208 If `ctx=None`, then the global context is used.
10209
10210 >>> v = FPVal(20.0, FPSort(8, 24))
10211 >>> v
10212 1.25*(2**4)
10213 >>> print("0x%.8x" % v.exponent_as_long(False))
10214 0x00000004
10215 >>> v = FPVal(2.25, FPSort(8, 24))
10216 >>> v
10217 1.125*(2**1)
10218 >>> v = FPVal(-2.25, FPSort(8, 24))
10219 >>> v
10220 -1.125*(2**1)
10221 >>> FPVal(-0.0, FPSort(8, 24))
10222 -0.0
10223 >>> FPVal(0.0, FPSort(8, 24))
10224 +0.0
10225 >>> FPVal(+0.0, FPSort(8, 24))
10226 +0.0
10227 """
10228 ctx = _get_ctx(ctx)
10229 if is_fp_sort(exp):
10230 fps = exp
10231 exp = None
10232 elif fps is None:
10233 fps = _dflt_fps(ctx)
10234 _z3_assert(is_fp_sort(fps), "sort mismatch")
10235 if exp is None:
10236 exp = 0
10237 val = _to_float_str(sig)
10238 if val == "NaN" or val == "nan":
10239 return fpNaN(fps)
10240 elif val == "-0.0":
10241 return fpMinusZero(fps)
10242 elif val == "0.0" or val == "+0.0":
10243 return fpPlusZero(fps)
10244 elif val == "+oo" or val == "+inf" or val == "+Inf":
10245 return fpPlusInfinity(fps)
10246 elif val == "-oo" or val == "-inf" or val == "-Inf":
10247 return fpMinusInfinity(fps)
10248 else:
10249 return FPNumRef(Z3_mk_numeral(ctx.ref(), val, fps.ast), ctx)
10250
10251

◆ fpZero()

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

Definition at line 10199 of file z3py.py.

10199def fpZero(s, negative):
10200 """Create a Z3 floating-point +0.0 or -0.0 term."""
10201 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10202 _z3_assert(isinstance(negative, bool), "expected Boolean flag")
10203 return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, negative), s.ctx)
10204
10205

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

1818def FreshBool(prefix="b", ctx=None):
1819 """Return a fresh Boolean constant in the given context using the given prefix.
1820
1821 If `ctx=None`, then the global context is used.
1822
1823 >>> b1 = FreshBool()
1824 >>> b2 = FreshBool()
1825 >>> eq(b1, b2)
1826 False
1827 """
1828 ctx = _get_ctx(ctx)
1829 return BoolRef(Z3_mk_fresh_const(ctx.ref(), prefix, BoolSort(ctx).ast), ctx)
1830
1831
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 1489 of file z3py.py.

1489def FreshConst(sort, prefix="c"):
1490 """Create a fresh constant of a specified sort"""
1491 ctx = _get_ctx(sort.ctx)
1492 return _to_expr_ref(Z3_mk_fresh_const(ctx.ref(), prefix, sort.ast), ctx)
1493
1494

◆ FreshFunction()

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

Definition at line 904 of file z3py.py.

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

3340def FreshInt(prefix="x", ctx=None):
3341 """Return a fresh integer constant in the given context using the given prefix.
3342
3343 >>> x = FreshInt()
3344 >>> y = FreshInt()
3345 >>> eq(x, y)
3346 False
3347 >>> x.sort()
3348 Int
3349 """
3350 ctx = _get_ctx(ctx)
3351 return ArithRef(Z3_mk_fresh_const(ctx.ref(), prefix, IntSort(ctx).ast), ctx)
3352
3353

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

3397def FreshReal(prefix="b", ctx=None):
3398 """Return a fresh real constant in the given context using the given prefix.
3399
3400 >>> x = FreshReal()
3401 >>> y = FreshReal()
3402 >>> eq(x, y)
3403 False
3404 >>> x.sort()
3405 Real
3406 """
3407 ctx = _get_ctx(ctx)
3408 return ArithRef(Z3_mk_fresh_const(ctx.ref(), prefix, RealSort(ctx).ast), ctx)
3409
3410

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

11155def Full(s):
11156 """Create the regular expression that accepts the universal language
11157 >>> e = Full(ReSort(SeqSort(IntSort())))
11158 >>> print(e)
11159 Full(ReSort(Seq(Int)))
11160 >>> e1 = Full(ReSort(StringSort()))
11161 >>> print(e1)
11162 Full(ReSort(String))
11163 """
11164 if isinstance(s, ReSortRef):
11165 return ReRef(Z3_mk_re_full(s.ctx_ref(), s.ast), s.ctx)
11166 raise Z3Exception("Non-sequence, non-regular expression sort passed to Full")
11167
11168
11169
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 4984 of file z3py.py.

4984def FullSet(s):
4985 """Create the full set
4986 >>> FullSet(IntSort())
4987 K(Int, True)
4988 """
4989 ctx = s.ctx
4990 return ArrayRef(Z3_mk_full_set(ctx.ref(), s.ast), ctx)
4991
4992
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 881 of file z3py.py.

881def Function(name, *sig):
882 """Create a new Z3 uninterpreted function with the given sorts.
883
884 >>> f = Function('f', IntSort(), IntSort())
885 >>> f(f(0))
886 f(f(0))
887 """
888 sig = _get_args(sig)
889 if z3_debug():
890 _z3_assert(len(sig) > 0, "At least two arguments expected")
891 arity = len(sig) - 1
892 rng = sig[arity]
893 if z3_debug():
894 _z3_assert(is_sort(rng), "Z3 sort expected")
895 dom = (Sort * arity)()
896 for i in range(arity):
897 if z3_debug():
898 _z3_assert(is_sort(sig[i]), "Z3 sort expected")
899 dom[i] = sig[i].ast
900 ctx = rng.ctx
901 return FuncDeclRef(Z3_mk_func_decl(ctx.ref(), to_symbol(name, ctx), arity, dom, rng.ast), ctx)
902
903
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 6779 of file z3py.py.

6779def get_as_array_func(n):
6780 """Return the function declaration f associated with a Z3 expression of the form (_ as-array f)."""
6781 if z3_debug():
6782 _z3_assert(is_as_array(n), "as-array Z3 expression expected.")
6783 return FuncDeclRef(Z3_get_as_array_func_decl(n.ctx.ref(), n.as_ast()), n.ctx)
6784
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()

get_ctx ( ctx)

Definition at line 267 of file z3py.py.

267def get_ctx(ctx):
268 return _get_ctx(ctx)
269
270

◆ get_default_fp_sort()

get_default_fp_sort ( ctx = None)

Definition at line 9503 of file z3py.py.

9503def get_default_fp_sort(ctx=None):
9504 return FPSort(_dflt_fpsort_ebits, _dflt_fpsort_sbits, ctx)
9505
9506

◆ get_default_rounding_mode()

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

Definition at line 9470 of file z3py.py.

9470def get_default_rounding_mode(ctx=None):
9471 """Retrieves the global default rounding mode."""
9472 global _dflt_rounding_mode
9473 if _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO:
9474 return RTZ(ctx)
9475 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE:
9476 return RTN(ctx)
9477 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE:
9478 return RTP(ctx)
9479 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN:
9480 return RNE(ctx)
9481 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY:
9482 return RNA(ctx)
9483
9484

◆ get_full_version()

get_full_version ( )

Definition at line 101 of file z3py.py.

101def get_full_version():
102 return Z3_get_full_version()
103
104
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 4729 of file z3py.py.

4729def get_map_func(a):
4730 """Return the function declaration associated with a Z3 map array expression.
4731
4732 >>> f = Function('f', IntSort(), IntSort())
4733 >>> b = Array('b', IntSort(), IntSort())
4734 >>> a = Map(f, b)
4735 >>> eq(f, get_map_func(a))
4736 True
4737 >>> get_map_func(a)
4738 f
4739 >>> get_map_func(a)(0)
4740 f(0)
4741 """
4742 if z3_debug():
4743 _z3_assert(is_map(a), "Z3 array map expression expected.")
4744 return FuncDeclRef(
4746 a.ctx_ref(),
4747 Z3_get_decl_ast_parameter(a.ctx_ref(), a.decl().ast, 0),
4748 ),
4749 ctx=a.ctx,
4750 )
4751
4752
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 307 of file z3py.py.

307def get_param(name):
308 """Return the value of a Z3 global (or module) parameter
309
310 >>> get_param('nlsat.reorder')
311 'true'
312 """
313 ptr = (ctypes.c_char_p * 1)()
314 if Z3_global_param_get(str(name), ptr):
315 r = z3core._to_pystr(ptr[0])
316 return r
317 raise Z3Exception("failed to retrieve value for '%s'" % name)
318
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 1360 of file z3py.py.

1360def get_var_index(a):
1361 """Return the de-Bruijn index of the Z3 bounded variable `a`.
1362
1363 >>> x = Int('x')
1364 >>> y = Int('y')
1365 >>> is_var(x)
1366 False
1367 >>> is_const(x)
1368 True
1369 >>> f = Function('f', IntSort(), IntSort(), IntSort())
1370 >>> # Z3 replaces x and y with bound variables when ForAll is executed.
1371 >>> q = ForAll([x, y], f(x, y) == x + y)
1372 >>> q.body()
1373 f(Var(1), Var(0)) == Var(1) + Var(0)
1374 >>> b = q.body()
1375 >>> b.arg(0)
1376 f(Var(1), Var(0))
1377 >>> v1 = b.arg(0).arg(0)
1378 >>> v2 = b.arg(0).arg(1)
1379 >>> v1
1380 Var(1)
1381 >>> v2
1382 Var(0)
1383 >>> get_var_index(v1)
1384 1
1385 >>> get_var_index(v2)
1386 0
1387 """
1388 if z3_debug():
1389 _z3_assert(is_var(a), "Z3 bound variable expected")
1390 return int(Z3_get_index_value(a.ctx.ref(), a.as_ast()))
1391
1392
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 92 of file z3py.py.

92def get_version():
93 major = ctypes.c_uint(0)
94 minor = ctypes.c_uint(0)
95 build = ctypes.c_uint(0)
96 rev = ctypes.c_uint(0)
97 Z3_get_version(major, minor, build, rev)
98 return (major.value, minor.value, build.value, rev.value)
99
100
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 83 of file z3py.py.

83def get_version_string():
84 major = ctypes.c_uint(0)
85 minor = ctypes.c_uint(0)
86 build = ctypes.c_uint(0)
87 rev = ctypes.c_uint(0)
88 Z3_get_version(major, minor, build, rev)
89 return "%s.%s.%s" % (major.value, minor.value, build.value)
90
91

◆ help_simplify()

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

Definition at line 8976 of file z3py.py.

8976def help_simplify():
8977 """Return a string describing all options available for Z3 `simplify` procedure."""
8978 print(Z3_simplify_get_help(main_ctx().ref()))
8979
8980
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 1406 of file z3py.py.

1406def If(a, b, c, ctx=None):
1407 """Create a Z3 if-then-else expression.
1408
1409 >>> x = Int('x')
1410 >>> y = Int('y')
1411 >>> max = If(x > y, x, y)
1412 >>> max
1413 If(x > y, x, y)
1414 >>> simplify(max)
1415 If(x <= y, y, x)
1416 """
1417 if isinstance(a, Probe) or isinstance(b, Tactic) or isinstance(c, Tactic):
1418 return Cond(a, b, c, ctx)
1419 else:
1420 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b, c], ctx))
1421 s = BoolSort(ctx)
1422 a = s.cast(a)
1423 b, c = _coerce_exprs(b, c, ctx)
1424 if z3_debug():
1425 _z3_assert(a.ctx == b.ctx, "Context mismatch")
1426 return _to_expr_ref(Z3_mk_ite(ctx.ref(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
1427
1428
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__(), ArithRef.__mul__(), and BoolRef.__mul__().

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

1832def Implies(a, b, ctx=None):
1833 """Create a Z3 implies expression.
1834
1835 >>> p, q = Bools('p q')
1836 >>> Implies(p, q)
1837 Implies(p, q)
1838 """
1839 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1840 s = BoolSort(ctx)
1841 a = s.cast(a)
1842 b = s.cast(b)
1843 return BoolRef(Z3_mk_implies(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
1844
1845
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 11239 of file z3py.py.

11239def IndexOf(s, substr, offset=None):
11240 """Retrieve the index of substring within a string starting at a specified offset.
11241 >>> simplify(IndexOf("abcabc", "bc", 0))
11242 1
11243 >>> simplify(IndexOf("abcabc", "bc", 2))
11244 4
11245 """
11246 if offset is None:
11247 offset = IntVal(0)
11248 ctx = None
11249 if is_expr(offset):
11250 ctx = offset.ctx
11251 ctx = _get_ctx2(s, substr, ctx)
11252 s = _coerce_seq(s, ctx)
11253 substr = _coerce_seq(substr, ctx)
11254 if _is_int(offset):
11255 offset = IntVal(offset, ctx)
11256 return ArithRef(Z3_mk_seq_index(s.ctx_ref(), s.as_ast(), substr.as_ast(), offset.as_ast()), s.ctx)
11257
11258
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 11378 of file z3py.py.

11378def InRe(s, re):
11379 """Create regular expression membership test
11380 >>> re = Union(Re("a"),Re("b"))
11381 >>> print (simplify(InRe("a", re)))
11382 True
11383 >>> print (simplify(InRe("b", re)))
11384 True
11385 >>> print (simplify(InRe("c", re)))
11386 False
11387 """
11388 s = _coerce_seq(s, re.ctx)
11389 return BoolRef(Z3_mk_seq_in_re(s.ctx_ref(), s.as_ast(), re.as_ast()), s.ctx)
11390
11391
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 3301 of file z3py.py.

3301def Int(name, ctx=None):
3302 """Return an integer constant named `name`. If `ctx=None`, then the global context is used.
3303
3304 >>> x = Int('x')
3305 >>> is_int(x)
3306 True
3307 >>> is_int(x + 1)
3308 True
3309 """
3310 ctx = _get_ctx(ctx)
3311 return ArithRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), IntSort(ctx).ast), ctx)
3312
3313

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

4049def Int2BV(a, num_bits):
4050 """Return the z3 expression Int2BV(a, num_bits).
4051 It is a bit-vector of width num_bits and represents the
4052 modulo of a by 2^num_bits
4053 """
4054 ctx = a.ctx
4055 return BitVecRef(Z3_mk_int2bv(ctx.ref(), num_bits, a.as_ast()), ctx)
4056
4057
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 11412 of file z3py.py.

11412def Intersect(*args):
11413 """Create intersection of regular expressions.
11414 >>> re = Intersect(Re("a"), Re("b"), Re("c"))
11415 """
11416 args = _get_args(args)
11417 sz = len(args)
11418 if z3_debug():
11419 _z3_assert(sz > 0, "At least one argument expected.")
11420 _z3_assert(all([is_re(a) for a in args]), "All arguments must be regular expressions.")
11421 if sz == 1:
11422 return args[0]
11423 ctx = args[0].ctx
11424 v = (Ast * sz)()
11425 for i in range(sz):
11426 v[i] = args[i].as_ast()
11427 return ReRef(Z3_mk_re_intersect(ctx.ref(), sz, v), ctx)
11428
11429
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 3314 of file z3py.py.

3314def Ints(names, ctx=None):
3315 """Return a tuple of Integer constants.
3316
3317 >>> x, y, z = Ints('x y z')
3318 >>> Sum(x, y, z)
3319 x + y + z
3320 """
3321 ctx = _get_ctx(ctx)
3322 if isinstance(names, str):
3323 names = names.split(" ")
3324 return [Int(name, ctx) for name in names]
3325
3326

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

3195def IntSort(ctx=None):
3196 """Return the integer sort in the given context. If `ctx=None`, then the global context is used.
3197
3198 >>> IntSort()
3199 Int
3200 >>> x = Const('x', IntSort())
3201 >>> is_int(x)
3202 True
3203 >>> x.sort() == IntSort()
3204 True
3205 >>> x.sort() == BoolSort()
3206 False
3207 """
3208 ctx = _get_ctx(ctx)
3209 return ArithSortRef(Z3_mk_int_sort(ctx.ref()), ctx)
3210
3211
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 11320 of file z3py.py.

11320def IntToStr(s):
11321 """Convert integer expression to string"""
11322 if not is_expr(s):
11323 s = _py2expr(s)
11324 return SeqRef(Z3_mk_int_to_str(s.ctx_ref(), s.as_ast()), s.ctx)
11325
11326
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 3241 of file z3py.py.

3241def IntVal(val, ctx=None):
3242 """Return a Z3 integer value. If `ctx=None`, then the global context is used.
3243
3244 >>> IntVal(1)
3245 1
3246 >>> IntVal("100")
3247 100
3248 """
3249 ctx = _get_ctx(ctx)
3250 return IntNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), IntSort(ctx).ast), ctx)
3251
3252

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

3327def IntVector(prefix, sz, ctx=None):
3328 """Return a list of integer constants of size `sz`.
3329
3330 >>> X = IntVector('x', 3)
3331 >>> X
3332 [x__0, x__1, x__2]
3333 >>> Sum(X)
3334 x__0 + x__1 + x__2
3335 """
3336 ctx = _get_ctx(ctx)
3337 return [Int("%s__%s" % (prefix, i), ctx) for i in range(sz)]
3338
3339

◆ is_add()

is_add ( a)
Return `True` if `a` is an expression of the form b + c.

>>> x, y = Ints('x y')
>>> is_add(x + y)
True
>>> is_add(x - y)
False

Definition at line 2849 of file z3py.py.

2849def is_add(a):
2850 """Return `True` if `a` is an expression of the form b + c.
2851
2852 >>> x, y = Ints('x y')
2853 >>> is_add(x + y)
2854 True
2855 >>> is_add(x - y)
2856 False
2857 """
2858 return is_app_of(a, Z3_OP_ADD)
2859
2860

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

2835def is_algebraic_value(a):
2836 """Return `True` if `a` is an algebraic value of sort Real.
2837
2838 >>> is_algebraic_value(RealVal("3/5"))
2839 False
2840 >>> n = simplify(Sqrt(2))
2841 >>> n
2842 1.4142135623?
2843 >>> is_algebraic_value(n)
2844 True
2845 """
2846 return is_arith(a) and a.is_real() and _is_algebraic(a.ctx, a.as_ast())
2847
2848

◆ is_and()

is_and ( a)
Return `True` if `a` is a Z3 and expression.

>>> p, q = Bools('p q')
>>> is_and(And(p, q))
True
>>> is_and(Or(p, q))
False

Definition at line 1668 of file z3py.py.

1668def is_and(a):
1669 """Return `True` if `a` is a Z3 and expression.
1670
1671 >>> p, q = Bools('p q')
1672 >>> is_and(And(p, q))
1673 True
1674 >>> is_and(Or(p, q))
1675 False
1676 """
1677 return is_app_of(a, Z3_OP_AND)
1678
1679

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

1290def is_app(a):
1291 """Return `True` if `a` is a Z3 function application.
1292
1293 Note that, constants are function applications with 0 arguments.
1294
1295 >>> a = Int('a')
1296 >>> is_app(a)
1297 True
1298 >>> is_app(a + 1)
1299 True
1300 >>> is_app(IntSort())
1301 False
1302 >>> is_app(1)
1303 False
1304 >>> is_app(IntVal(1))
1305 True
1306 >>> x = Int('x')
1307 >>> is_app(ForAll(x, x >= 0))
1308 False
1309 """
1310 if not isinstance(a, ExprRef):
1311 return False
1312 k = _ast_kind(a.ctx, a)
1313 return k == Z3_NUMERAL_AST or k == Z3_APP_AST
1314
1315

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

◆ is_app_of()

is_app_of ( a,
k )
Return `True` if `a` is an application of the given kind `k`.

>>> x = Int('x')
>>> n = x + 1
>>> is_app_of(n, Z3_OP_ADD)
True
>>> is_app_of(n, Z3_OP_MUL)
False

Definition at line 1393 of file z3py.py.

1393def is_app_of(a, k):
1394 """Return `True` if `a` is an application of the given kind `k`.
1395
1396 >>> x = Int('x')
1397 >>> n = x + 1
1398 >>> is_app_of(n, Z3_OP_ADD)
1399 True
1400 >>> is_app_of(n, Z3_OP_MUL)
1401 False
1402 """
1403 return is_app(a) and a.kind() == k
1404
1405

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

2722def is_arith(a):
2723 """Return `True` if `a` is an arithmetical expression.
2724
2725 >>> x = Int('x')
2726 >>> is_arith(x)
2727 True
2728 >>> is_arith(x + 1)
2729 True
2730 >>> is_arith(1)
2731 False
2732 >>> is_arith(IntVal(1))
2733 True
2734 >>> y = Real('y')
2735 >>> is_arith(y)
2736 True
2737 >>> is_arith(y + 1)
2738 True
2739 """
2740 return isinstance(a, ArithRef)
2741
2742

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

◆ is_arith_sort()

is_arith_sort ( s)
Return `True` if s is an arithmetical sort (type).

>>> is_arith_sort(IntSort())
True
>>> is_arith_sort(RealSort())
True
>>> is_arith_sort(BoolSort())
False
>>> n = Int('x') + 1
>>> is_arith_sort(n.sort())
True

Definition at line 2421 of file z3py.py.

2421def is_arith_sort(s):
2422 """Return `True` if s is an arithmetical sort (type).
2423
2424 >>> is_arith_sort(IntSort())
2425 True
2426 >>> is_arith_sort(RealSort())
2427 True
2428 >>> is_arith_sort(BoolSort())
2429 False
2430 >>> n = Int('x') + 1
2431 >>> is_arith_sort(n.sort())
2432 True
2433 """
2434 return isinstance(s, ArithSortRef)
2435
2436

Referenced by ArithSortRef.subsort().

◆ is_array()

is_array ( a)
Return `True` if `a` is a Z3 array expression.

>>> a = Array('a', IntSort(), IntSort())
>>> is_array(a)
True
>>> is_array(Store(a, 0, 1))
True
>>> is_array(a[0])
False

Definition at line 4664 of file z3py.py.

4664def is_array(a):
4665 """Return `True` if `a` is a Z3 array expression.
4666
4667 >>> a = Array('a', IntSort(), IntSort())
4668 >>> is_array(a)
4669 True
4670 >>> is_array(Store(a, 0, 1))
4671 True
4672 >>> is_array(a[0])
4673 False
4674 """
4675 return isinstance(a, ArrayRef)
4676
4677

Referenced by Ext(), and Map().

◆ is_array_sort()

is_array_sort ( a)

Definition at line 4660 of file z3py.py.

4660def is_array_sort(a):
4661 return Z3_get_sort_kind(a.ctx.ref(), Z3_get_sort(a.ctx.ref(), a.ast)) == Z3_ARRAY_SORT
4662
4663

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

6774def is_as_array(n):
6775 """Return true if n is a Z3 expression of the form (_ as-array f)."""
6776 return isinstance(n, ExprRef) and Z3_is_as_array(n.ctx.ref(), n.as_ast())
6777
6778
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()

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

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

Definition at line 451 of file z3py.py.

451def is_ast(a):
452 """Return `True` if `a` is an AST node.
453
454 >>> is_ast(10)
455 False
456 >>> is_ast(IntVal(10))
457 True
458 >>> is_ast(Int('x'))
459 True
460 >>> is_ast(BoolSort())
461 True
462 >>> is_ast(Function('f', IntSort(), IntSort()))
463 True
464 >>> is_ast("x")
465 False
466 >>> is_ast(Solver())
467 False
468 """
469 return isinstance(a, AstRef)
470
471

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

◆ is_bool()

is_bool ( a)
Return `True` if `a` is a Z3 Boolean expression.

>>> p = Bool('p')
>>> is_bool(p)
True
>>> q = Bool('q')
>>> is_bool(And(p, q))
True
>>> x = Real('x')
>>> is_bool(x)
False
>>> is_bool(x == 0)
True

Definition at line 1618 of file z3py.py.

1618def is_bool(a):
1619 """Return `True` if `a` is a Z3 Boolean expression.
1620
1621 >>> p = Bool('p')
1622 >>> is_bool(p)
1623 True
1624 >>> q = Bool('q')
1625 >>> is_bool(And(p, q))
1626 True
1627 >>> x = Real('x')
1628 >>> is_bool(x)
1629 False
1630 >>> is_bool(x == 0)
1631 True
1632 """
1633 return isinstance(a, BoolRef)
1634
1635

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

3997def is_bv(a):
3998 """Return `True` if `a` is a Z3 bit-vector expression.
3999
4000 >>> b = BitVec('b', 32)
4001 >>> is_bv(b)
4002 True
4003 >>> is_bv(b + 10)
4004 True
4005 >>> is_bv(Int('x'))
4006 False
4007 """
4008 return isinstance(a, BitVecRef)
4009
4010

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

3529def is_bv_sort(s):
3530 """Return True if `s` is a Z3 bit-vector sort.
3531
3532 >>> is_bv_sort(BitVecSort(32))
3533 True
3534 >>> is_bv_sort(IntSort())
3535 False
3536 """
3537 return isinstance(s, BitVecSortRef)
3538
3539

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

4011def is_bv_value(a):
4012 """Return `True` if `a` is a Z3 bit-vector numeral value.
4013
4014 >>> b = BitVec('b', 32)
4015 >>> is_bv_value(b)
4016 False
4017 >>> b = BitVecVal(10, 32)
4018 >>> b
4019 10
4020 >>> is_bv_value(b)
4021 True
4022 """
4023 return is_bv(a) and _is_numeral(a.ctx, a.as_ast())
4024
4025

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

1316def is_const(a):
1317 """Return `True` if `a` is Z3 constant/variable expression.
1318
1319 >>> a = Int('a')
1320 >>> is_const(a)
1321 True
1322 >>> is_const(a + 1)
1323 False
1324 >>> is_const(1)
1325 False
1326 >>> is_const(IntVal(1))
1327 True
1328 >>> x = Int('x')
1329 >>> is_const(ForAll(x, x >= 0))
1330 False
1331 """
1332 return is_app(a) and a.num_args() == 0
1333
1334

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

4678def is_const_array(a):
4679 """Return `True` if `a` is a Z3 constant array.
4680
4681 >>> a = K(IntSort(), 10)
4682 >>> is_const_array(a)
4683 True
4684 >>> a = Array('a', IntSort(), IntSort())
4685 >>> is_const_array(a)
4686 False
4687 """
4688 return is_app_of(a, Z3_OP_CONST_ARRAY)
4689
4690

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

4720def is_default(a):
4721 """Return `True` if `a` is a Z3 default array expression.
4722 >>> d = Default(K(IntSort(), 10))
4723 >>> is_default(d)
4724 True
4725 """
4726 return is_app_of(a, Z3_OP_ARRAY_DEFAULT)
4727
4728

◆ is_distinct()

is_distinct ( a)
Return `True` if `a` is a Z3 distinct expression.

>>> x, y, z = Ints('x y z')
>>> is_distinct(x == y)
False
>>> is_distinct(Distinct(x, y, z))
True

Definition at line 1726 of file z3py.py.

1726def is_distinct(a):
1727 """Return `True` if `a` is a Z3 distinct expression.
1728
1729 >>> x, y, z = Ints('x y z')
1730 >>> is_distinct(x == y)
1731 False
1732 >>> is_distinct(Distinct(x, y, z))
1733 True
1734 """
1735 return is_app_of(a, Z3_OP_DISTINCT)
1736
1737

◆ is_div()

is_div ( a)
Return `True` if `a` is an expression of the form b / c.

>>> x, y = Reals('x y')
>>> is_div(x / y)
True
>>> is_div(x + y)
False
>>> x, y = Ints('x y')
>>> is_div(x / y)
False
>>> is_idiv(x / y)
True

Definition at line 2885 of file z3py.py.

2885def is_div(a):
2886 """Return `True` if `a` is an expression of the form b / c.
2887
2888 >>> x, y = Reals('x y')
2889 >>> is_div(x / y)
2890 True
2891 >>> is_div(x + y)
2892 False
2893 >>> x, y = Ints('x y')
2894 >>> is_div(x / y)
2895 False
2896 >>> is_idiv(x / y)
2897 True
2898 """
2899 return is_app_of(a, Z3_OP_DIV)
2900
2901

◆ is_eq()

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

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

Definition at line 1716 of file z3py.py.

1716def is_eq(a):
1717 """Return `True` if `a` is a Z3 equality expression.
1718
1719 >>> x, y = Ints('x y')
1720 >>> is_eq(x == y)
1721 True
1722 """
1723 return is_app_of(a, Z3_OP_EQ)
1724
1725

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

1267def is_expr(a):
1268 """Return `True` if `a` is a Z3 expression.
1269
1270 >>> a = Int('a')
1271 >>> is_expr(a)
1272 True
1273 >>> is_expr(a + 1)
1274 True
1275 >>> is_expr(IntSort())
1276 False
1277 >>> is_expr(1)
1278 False
1279 >>> is_expr(IntVal(1))
1280 True
1281 >>> x = Int('x')
1282 >>> is_expr(ForAll(x, x >= 0))
1283 True
1284 >>> is_expr(FPVal(1.0))
1285 True
1286 """
1287 return isinstance(a, ExprRef)
1288
1289

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

◆ is_false()

is_false ( a)
Return `True` if `a` is the Z3 false expression.

>>> p = Bool('p')
>>> is_false(p)
False
>>> is_false(False)
False
>>> is_false(BoolVal(False))
True

Definition at line 1654 of file z3py.py.

1654def is_false(a):
1655 """Return `True` if `a` is the Z3 false expression.
1656
1657 >>> p = Bool('p')
1658 >>> is_false(p)
1659 False
1660 >>> is_false(False)
1661 False
1662 >>> is_false(BoolVal(False))
1663 True
1664 """
1665 return is_app_of(a, Z3_OP_FALSE)
1666
1667

Referenced by AstRef.__bool__().

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

7854def is_finite_domain(a):
7855 """Return `True` if `a` is a Z3 finite-domain expression.
7856
7857 >>> s = FiniteDomainSort('S', 100)
7858 >>> b = Const('b', s)
7859 >>> is_finite_domain(b)
7860 True
7861 >>> is_finite_domain(Int('x'))
7862 False
7863 """
7864 return isinstance(a, FiniteDomainRef)
7865
7866

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

7831def is_finite_domain_sort(s):
7832 """Return True if `s` is a Z3 finite-domain sort.
7833
7834 >>> is_finite_domain_sort(FiniteDomainSort('S', 100))
7835 True
7836 >>> is_finite_domain_sort(IntSort())
7837 False
7838 """
7839 return isinstance(s, FiniteDomainSortRef)
7840
7841

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

7908def is_finite_domain_value(a):
7909 """Return `True` if `a` is a Z3 finite-domain value.
7910
7911 >>> s = FiniteDomainSort('S', 100)
7912 >>> b = Const('b', s)
7913 >>> is_finite_domain_value(b)
7914 False
7915 >>> b = FiniteDomainVal(10, s)
7916 >>> b
7917 10
7918 >>> is_finite_domain_value(b)
7919 True
7920 """
7921 return is_finite_domain(a) and _is_numeral(a.ctx, a.as_ast())
7922
7923

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

10052def is_fp(a):
10053 """Return `True` if `a` is a Z3 floating-point expression.
10054
10055 >>> b = FP('b', FPSort(8, 24))
10056 >>> is_fp(b)
10057 True
10058 >>> is_fp(b + 1.0)
10059 True
10060 >>> is_fp(Int('x'))
10061 False
10062 """
10063 return isinstance(a, FPRef)
10064
10065

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

9636def is_fp_sort(s):
9637 """Return True if `s` is a Z3 floating-point sort.
9638
9639 >>> is_fp_sort(FPSort(8, 24))
9640 True
9641 >>> is_fp_sort(IntSort())
9642 False
9643 """
9644 return isinstance(s, FPSortRef)
9645
9646

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

10066def is_fp_value(a):
10067 """Return `True` if `a` is a Z3 floating-point numeral value.
10068
10069 >>> b = FP('b', FPSort(8, 24))
10070 >>> is_fp_value(b)
10071 False
10072 >>> b = FPVal(1.0, FPSort(8, 24))
10073 >>> b
10074 1
10075 >>> is_fp_value(b)
10076 True
10077 """
10078 return is_fp(a) and _is_numeral(a.ctx, a.ast)
10079
10080

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

9896def is_fprm(a):
9897 """Return `True` if `a` is a Z3 floating-point rounding mode expression.
9898
9899 >>> rm = RNE()
9900 >>> is_fprm(rm)
9901 True
9902 >>> rm = 1.0
9903 >>> is_fprm(rm)
9904 False
9905 """
9906 return isinstance(a, FPRMRef)
9907
9908

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

9647def is_fprm_sort(s):
9648 """Return True if `s` is a Z3 floating-point rounding mode sort.
9649
9650 >>> is_fprm_sort(FPSort(8, 24))
9651 False
9652 >>> is_fprm_sort(RNE().sort())
9653 True
9654 """
9655 return isinstance(s, FPRMSortRef)
9656
9657# FP Expressions
9658
9659

◆ is_fprm_value()

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

Definition at line 9909 of file z3py.py.

9909def is_fprm_value(a):
9910 """Return `True` if `a` is a Z3 floating-point rounding mode numeral value."""
9911 return is_fprm(a) and _is_numeral(a.ctx, a.ast)
9912
9913# FP Numerals
9914
9915

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

868def is_func_decl(a):
869 """Return `True` if `a` is a Z3 function declaration.
870
871 >>> f = Function('f', IntSort(), IntSort())
872 >>> is_func_decl(f)
873 True
874 >>> x = Real('x')
875 >>> is_func_decl(x)
876 False
877 """
878 return isinstance(a, FuncDeclRef)
879
880

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

◆ is_ge()

is_ge ( a)
Return `True` if `a` is an expression of the form b >= c.

>>> x, y = Ints('x y')
>>> is_ge(x >= y)
True
>>> is_ge(x == y)
False

Definition at line 2950 of file z3py.py.

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

◆ is_gt()

is_gt ( a)
Return `True` if `a` is an expression of the form b > c.

>>> x, y = Ints('x y')
>>> is_gt(x > y)
True
>>> is_gt(x == y)
False

Definition at line 2962 of file z3py.py.

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

◆ is_idiv()

is_idiv ( a)
Return `True` if `a` is an expression of the form b div c.

>>> x, y = Ints('x y')
>>> is_idiv(x / y)
True
>>> is_idiv(x + y)
False

Definition at line 2902 of file z3py.py.

2902def is_idiv(a):
2903 """Return `True` if `a` is an expression of the form b div c.
2904
2905 >>> x, y = Ints('x y')
2906 >>> is_idiv(x / y)
2907 True
2908 >>> is_idiv(x + y)
2909 False
2910 """
2911 return is_app_of(a, Z3_OP_IDIV)
2912
2913

◆ is_implies()

is_implies ( 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 1692 of file z3py.py.

1692def is_implies(a):
1693 """Return `True` if `a` is a Z3 implication expression.
1694
1695 >>> p, q = Bools('p q')
1696 >>> is_implies(Implies(p, q))
1697 True
1698 >>> is_implies(And(p, q))
1699 False
1700 """
1701 return is_app_of(a, Z3_OP_IMPLIES)
1702
1703

◆ is_int()

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

2743def is_int(a):
2744 """Return `True` if `a` is an integer expression.
2745
2746 >>> x = Int('x')
2747 >>> is_int(x + 1)
2748 True
2749 >>> is_int(1)
2750 False
2751 >>> is_int(IntVal(1))
2752 True
2753 >>> y = Real('y')
2754 >>> is_int(y)
2755 False
2756 >>> is_int(y + 1)
2757 False
2758 """
2759 return is_arith(a) and a.is_int()
2760
2761

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

2789def is_int_value(a):
2790 """Return `True` if `a` is an integer value of sort Int.
2791
2792 >>> is_int_value(IntVal(1))
2793 True
2794 >>> is_int_value(1)
2795 False
2796 >>> is_int_value(Int('x'))
2797 False
2798 >>> n = Int('x') + 1
2799 >>> n
2800 x + 1
2801 >>> n.arg(1)
2802 1
2803 >>> is_int_value(n.arg(1))
2804 True
2805 >>> is_int_value(RealVal("1/3"))
2806 False
2807 >>> is_int_value(RealVal(1))
2808 False
2809 """
2810 return is_arith(a) and a.is_int() and _is_numeral(a.ctx, a.as_ast())
2811
2812

◆ is_is_int()

is_is_int ( a)
Return `True` if `a` is an expression of the form IsInt(b).

>>> x = Real('x')
>>> is_is_int(IsInt(x))
True
>>> is_is_int(x)
False

Definition at line 2974 of file z3py.py.

2974def is_is_int(a):
2975 """Return `True` if `a` is an expression of the form IsInt(b).
2976
2977 >>> x = Real('x')
2978 >>> is_is_int(IsInt(x))
2979 True
2980 >>> is_is_int(x)
2981 False
2982 """
2983 return is_app_of(a, Z3_OP_IS_INT)
2984
2985

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

4691def is_K(a):
4692 """Return `True` if `a` is a Z3 constant array.
4693
4694 >>> a = K(IntSort(), 10)
4695 >>> is_K(a)
4696 True
4697 >>> a = Array('a', IntSort(), IntSort())
4698 >>> is_K(a)
4699 False
4700 """
4701 return is_app_of(a, Z3_OP_CONST_ARRAY)
4702
4703

◆ is_le()

is_le ( a)
Return `True` if `a` is an expression of the form b <= c.

>>> x, y = Ints('x y')
>>> is_le(x <= y)
True
>>> is_le(x < y)
False

Definition at line 2926 of file z3py.py.

2926def is_le(a):
2927 """Return `True` if `a` is an expression of the form b <= c.
2928
2929 >>> x, y = Ints('x y')
2930 >>> is_le(x <= y)
2931 True
2932 >>> is_le(x < y)
2933 False
2934 """
2935 return is_app_of(a, Z3_OP_LE)
2936
2937

◆ is_lt()

is_lt ( a)
Return `True` if `a` is an expression of the form b < c.

>>> x, y = Ints('x y')
>>> is_lt(x < y)
True
>>> is_lt(x == y)
False

Definition at line 2938 of file z3py.py.

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

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

4704def is_map(a):
4705 """Return `True` if `a` is a Z3 map array expression.
4706
4707 >>> f = Function('f', IntSort(), IntSort())
4708 >>> b = Array('b', IntSort(), IntSort())
4709 >>> a = Map(f, b)
4710 >>> a
4711 Map(f, b)
4712 >>> is_map(a)
4713 True
4714 >>> is_map(b)
4715 False
4716 """
4717 return is_app_of(a, Z3_OP_ARRAY_MAP)
4718
4719

Referenced by get_map_func().

◆ is_mod()

is_mod ( a)
Return `True` if `a` is an expression of the form b % c.

>>> x, y = Ints('x y')
>>> is_mod(x % y)
True
>>> is_mod(x + y)
False

Definition at line 2914 of file z3py.py.

2914def is_mod(a):
2915 """Return `True` if `a` is an expression of the form b % c.
2916
2917 >>> x, y = Ints('x y')
2918 >>> is_mod(x % y)
2919 True
2920 >>> is_mod(x + y)
2921 False
2922 """
2923 return is_app_of(a, Z3_OP_MOD)
2924
2925

◆ is_mul()

is_mul ( a)
Return `True` if `a` is an expression of the form b * c.

>>> x, y = Ints('x y')
>>> is_mul(x * y)
True
>>> is_mul(x - y)
False

Definition at line 2861 of file z3py.py.

2861def is_mul(a):
2862 """Return `True` if `a` is an expression of the form b * c.
2863
2864 >>> x, y = Ints('x y')
2865 >>> is_mul(x * y)
2866 True
2867 >>> is_mul(x - y)
2868 False
2869 """
2870 return is_app_of(a, Z3_OP_MUL)
2871
2872

◆ is_not()

is_not ( a)
Return `True` if `a` is a Z3 not expression.

>>> p = Bool('p')
>>> is_not(p)
False
>>> is_not(Not(p))
True

Definition at line 1704 of file z3py.py.

1704def is_not(a):
1705 """Return `True` if `a` is a Z3 not expression.
1706
1707 >>> p = Bool('p')
1708 >>> is_not(p)
1709 False
1710 >>> is_not(Not(p))
1711 True
1712 """
1713 return is_app_of(a, Z3_OP_NOT)
1714
1715

Referenced by mk_not().

◆ is_or()

is_or ( a)
Return `True` if `a` is a Z3 or expression.

>>> p, q = Bools('p q')
>>> is_or(Or(p, q))
True
>>> is_or(And(p, q))
False

Definition at line 1680 of file z3py.py.

1680def is_or(a):
1681 """Return `True` if `a` is a Z3 or expression.
1682
1683 >>> p, q = Bools('p q')
1684 >>> is_or(Or(p, q))
1685 True
1686 >>> is_or(And(p, q))
1687 False
1688 """
1689 return is_app_of(a, Z3_OP_OR)
1690
1691

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

1980def is_pattern(a):
1981 """Return `True` if `a` is a Z3 pattern (hint for quantifier instantiation.
1982
1983 >>> f = Function('f', IntSort(), IntSort())
1984 >>> x = Int('x')
1985 >>> q = ForAll(x, f(x) == 0, patterns = [ f(x) ])
1986 >>> q
1987 ForAll(x, f(x) == 0)
1988 >>> q.num_patterns()
1989 1
1990 >>> is_pattern(q.pattern(0))
1991 True
1992 >>> q.pattern(0)
1993 f(Var(0))
1994 """
1995 return isinstance(a, PatternRef)
1996
1997

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

8817def is_probe(p):
8818 """Return `True` if `p` is a Z3 probe.
8819
8820 >>> is_probe(Int('x'))
8821 False
8822 >>> is_probe(Probe('memory'))
8823 True
8824 """
8825 return isinstance(p, Probe)
8826
8827

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

2230def is_quantifier(a):
2231 """Return `True` if `a` is a Z3 quantifier.
2232
2233 >>> f = Function('f', IntSort(), IntSort())
2234 >>> x = Int('x')
2235 >>> q = ForAll(x, f(x) == 0)
2236 >>> is_quantifier(q)
2237 True
2238 >>> is_quantifier(f(x))
2239 False
2240 """
2241 return isinstance(a, QuantifierRef)
2242
2243

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

2813def is_rational_value(a):
2814 """Return `True` if `a` is rational value of sort Real.
2815
2816 >>> is_rational_value(RealVal(1))
2817 True
2818 >>> is_rational_value(RealVal("3/5"))
2819 True
2820 >>> is_rational_value(IntVal(1))
2821 False
2822 >>> is_rational_value(1)
2823 False
2824 >>> n = Real('x') + 1
2825 >>> n.arg(1)
2826 1
2827 >>> is_rational_value(n.arg(1))
2828 True
2829 >>> is_rational_value(Real('x'))
2830 False
2831 """
2832 return is_arith(a) and a.is_real() and _is_numeral(a.ctx, a.as_ast())
2833
2834

◆ is_re()

is_re ( s)

Definition at line 11374 of file z3py.py.

11374def is_re(s):
11375 return isinstance(s, ReRef)
11376
11377

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

2762def is_real(a):
2763 """Return `True` if `a` is a real expression.
2764
2765 >>> x = Int('x')
2766 >>> is_real(x + 1)
2767 False
2768 >>> y = Real('y')
2769 >>> is_real(y)
2770 True
2771 >>> is_real(y + 1)
2772 True
2773 >>> is_real(1)
2774 False
2775 >>> is_real(RealVal(1))
2776 True
2777 """
2778 return is_arith(a) and a.is_real()
2779
2780

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

4939def is_select(a):
4940 """Return `True` if `a` is a Z3 array select application.
4941
4942 >>> a = Array('a', IntSort(), IntSort())
4943 >>> is_select(a)
4944 False
4945 >>> i = Int('i')
4946 >>> is_select(a[i])
4947 True
4948 """
4949 return is_app_of(a, Z3_OP_SELECT)
4950
4951

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

11074def is_seq(a):
11075 """Return `True` if `a` is a Z3 sequence expression.
11076 >>> print (is_seq(Unit(IntVal(0))))
11077 True
11078 >>> print (is_seq(StringVal("abc")))
11079 True
11080 """
11081 return isinstance(a, SeqRef)
11082
11083

Referenced by Concat(), and Extract().

◆ is_sort()

is_sort ( s)
Return `True` if `s` is a Z3 sort.

>>> is_sort(IntSort())
True
>>> is_sort(Int('x'))
False
>>> is_expr(Int('x'))
True

Definition at line 647 of file z3py.py.

647def is_sort(s):
648 """Return `True` if `s` is a Z3 sort.
649
650 >>> is_sort(IntSort())
651 True
652 >>> is_sort(Int('x'))
653 False
654 >>> is_expr(Int('x'))
655 True
656 """
657 return isinstance(s, SortRef)
658
659

Referenced by _valid_accessor(), ArraySort(), CreateDatatypes(), 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 4952 of file z3py.py.

4952def is_store(a):
4953 """Return `True` if `a` is a Z3 array store application.
4954
4955 >>> a = Array('a', IntSort(), IntSort())
4956 >>> is_store(a)
4957 False
4958 >>> is_store(Store(a, 0, 1))
4959 True
4960 """
4961 return is_app_of(a, Z3_OP_STORE)
4962

◆ is_string()

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

Definition at line 11084 of file z3py.py.

11084def is_string(a):
11085 """Return `True` if `a` is a Z3 string expression.
11086 >>> print (is_string(StringVal("ab")))
11087 True
11088 """
11089 return isinstance(a, SeqRef) and a.is_string()
11090
11091

◆ is_string_value()

is_string_value ( a)
return 'True' if 'a' is a Z3 string constant expression.
>>> print (is_string_value(StringVal("a")))
True
>>> print (is_string_value(StringVal("a") + StringVal("b")))
False

Definition at line 11092 of file z3py.py.

11092def is_string_value(a):
11093 """return 'True' if 'a' is a Z3 string constant expression.
11094 >>> print (is_string_value(StringVal("a")))
11095 True
11096 >>> print (is_string_value(StringVal("a") + StringVal("b")))
11097 False
11098 """
11099 return isinstance(a, SeqRef) and a.is_string_value()
11100

◆ is_sub()

is_sub ( a)
Return `True` if `a` is an expression of the form b - c.

>>> x, y = Ints('x y')
>>> is_sub(x - y)
True
>>> is_sub(x + y)
False

Definition at line 2873 of file z3py.py.

2873def is_sub(a):
2874 """Return `True` if `a` is an expression of the form b - c.
2875
2876 >>> x, y = Ints('x y')
2877 >>> is_sub(x - y)
2878 True
2879 >>> is_sub(x + y)
2880 False
2881 """
2882 return is_app_of(a, Z3_OP_SUB)
2883
2884

◆ is_to_int()

is_to_int ( a)
Return `True` if `a` is an expression of the form ToInt(b).

>>> x = Real('x')
>>> n = ToInt(x)
>>> n
ToInt(x)
>>> is_to_int(n)
True
>>> is_to_int(x)
False

Definition at line 3001 of file z3py.py.

3001def is_to_int(a):
3002 """Return `True` if `a` is an expression of the form ToInt(b).
3003
3004 >>> x = Real('x')
3005 >>> n = ToInt(x)
3006 >>> n
3007 ToInt(x)
3008 >>> is_to_int(n)
3009 True
3010 >>> is_to_int(x)
3011 False
3012 """
3013 return is_app_of(a, Z3_OP_TO_INT)
3014
3015

◆ is_to_real()

is_to_real ( a)
Return `True` if `a` is an expression of the form ToReal(b).

>>> x = Int('x')
>>> n = ToReal(x)
>>> n
ToReal(x)
>>> is_to_real(n)
True
>>> is_to_real(x)
False

Definition at line 2986 of file z3py.py.

2986def is_to_real(a):
2987 """Return `True` if `a` is an expression of the form ToReal(b).
2988
2989 >>> x = Int('x')
2990 >>> n = ToReal(x)
2991 >>> n
2992 ToReal(x)
2993 >>> is_to_real(n)
2994 True
2995 >>> is_to_real(x)
2996 False
2997 """
2998 return is_app_of(a, Z3_OP_TO_REAL)
2999
3000

◆ is_true()

is_true ( a)
Return `True` if `a` is the Z3 true expression.

>>> p = Bool('p')
>>> is_true(p)
False
>>> is_true(simplify(p == p))
True
>>> x = Real('x')
>>> is_true(x == 0)
False
>>> # True is a Python Boolean expression
>>> is_true(True)
False

Definition at line 1636 of file z3py.py.

1636def is_true(a):
1637 """Return `True` if `a` is the Z3 true expression.
1638
1639 >>> p = Bool('p')
1640 >>> is_true(p)
1641 False
1642 >>> is_true(simplify(p == p))
1643 True
1644 >>> x = Real('x')
1645 >>> is_true(x == 0)
1646 False
1647 >>> # True is a Python Boolean expression
1648 >>> is_true(True)
1649 False
1650 """
1651 return is_app_of(a, Z3_OP_TRUE)
1652
1653

Referenced by AstRef.__bool__().

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

1335def is_var(a):
1336 """Return `True` if `a` is variable.
1337
1338 Z3 uses de-Bruijn indices for representing bound variables in
1339 quantifiers.
1340
1341 >>> x = Int('x')
1342 >>> is_var(x)
1343 False
1344 >>> is_const(x)
1345 True
1346 >>> f = Function('f', IntSort(), IntSort())
1347 >>> # Z3 replaces x with bound variables when ForAll is executed.
1348 >>> q = ForAll(x, f(x) == x)
1349 >>> b = q.body()
1350 >>> b
1351 f(Var(0)) == Var(0)
1352 >>> b.arg(1)
1353 Var(0)
1354 >>> is_var(b.arg(1))
1355 True
1356 """
1357 return is_expr(a) and _ast_kind(a.ctx, a) == Z3_VAR_AST
1358
1359

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

3447def IsInt(a):
3448 """ Return the Z3 predicate IsInt(a).
3449
3450 >>> x = Real('x')
3451 >>> IsInt(x + "1/2")
3452 IsInt(x + 1/2)
3453 >>> solve(IsInt(x + "1/2"), x > 0, x < 1)
3454 [x = 1/2]
3455 >>> solve(IsInt(x + "1/2"), x > 0, x < 1, x != "1/2")
3456 no solution
3457 """
3458 if z3_debug():
3459 _z3_assert(a.is_real(), "Z3 real expression expected.")
3460 ctx = a.ctx
3461 return BoolRef(Z3_mk_is_int(ctx.ref(), a.as_ast()), ctx)
3462
3463
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 5062 of file z3py.py.

5062def IsMember(e, s):
5063 """ Check if e is a member of set s
5064 >>> a = Const('a', SetSort(IntSort()))
5065 >>> IsMember(1, a)
5066 a[1]
5067 """
5068 ctx = _ctx_from_ast_arg_list([s, e])
5069 e = _py2expr(e, ctx)
5070 return BoolRef(Z3_mk_set_member(ctx.ref(), e.as_ast(), s.as_ast()), ctx)
5071
5072
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 5073 of file z3py.py.

5073def IsSubset(a, b):
5074 """ Check if a is a subset of b
5075 >>> a = Const('a', SetSort(IntSort()))
5076 >>> b = Const('b', SetSort(IntSort()))
5077 >>> IsSubset(a, b)
5078 subset(a, b)
5079 """
5080 ctx = _ctx_from_ast_arg_list([a, b])
5081 return BoolRef(Z3_mk_set_subset(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
5082
5083
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 4899 of file z3py.py.

4899def K(dom, v):
4900 """Return a Z3 constant array expression.
4901
4902 >>> a = K(IntSort(), 10)
4903 >>> a
4904 K(Int, 10)
4905 >>> a.sort()
4906 Array(Int, Int)
4907 >>> i = Int('i')
4908 >>> a[i]
4909 K(Int, 10)[i]
4910 >>> simplify(a[i])
4911 10
4912 """
4913 if z3_debug():
4914 _z3_assert(is_sort(dom), "Z3 sort expected")
4915 ctx = dom.ctx
4916 if not is_expr(v):
4917 v = _py2expr(v, ctx)
4918 return ArrayRef(Z3_mk_const_array(ctx.ref(), dom.ast, v.as_ast()), ctx)
4919
4920
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 2318 of file z3py.py.

2318def Lambda(vs, body):
2319 """Create a Z3 lambda expression.
2320
2321 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2322 >>> mem0 = Array('mem0', IntSort(), IntSort())
2323 >>> lo, hi, e, i = Ints('lo hi e i')
2324 >>> mem1 = Lambda([i], If(And(lo <= i, i <= hi), e, mem0[i]))
2325 >>> mem1
2326 Lambda(i, If(And(lo <= i, i <= hi), e, mem0[i]))
2327 """
2328 ctx = body.ctx
2329 if is_app(vs):
2330 vs = [vs]
2331 num_vars = len(vs)
2332 _vs = (Ast * num_vars)()
2333 for i in range(num_vars):
2334 # TODO: Check if is constant
2335 _vs[i] = vs[i].as_ast()
2336 return QuantifierRef(Z3_mk_lambda_const(ctx.ref(), num_vars, _vs, body.as_ast()), ctx)
2337
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 11259 of file z3py.py.

11259def LastIndexOf(s, substr):
11260 """Retrieve the last index of substring within a string"""
11261 ctx = None
11262 ctx = _get_ctx2(s, substr, ctx)
11263 s = _coerce_seq(s, ctx)
11264 substr = _coerce_seq(substr, ctx)
11265 return ArithRef(Z3_mk_seq_last_index(s.ctx_ref(), s.as_ast(), substr.as_ast()), s.ctx)
11266
11267
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 11268 of file z3py.py.

11268def Length(s):
11269 """Obtain the length of a sequence 's'
11270 >>> l = Length(StringVal("abc"))
11271 >>> simplify(l)
11272 3
11273 """
11274 s = _coerce_seq(s)
11275 return ArithRef(Z3_mk_seq_length(s.ctx_ref(), s.as_ast()), s.ctx)
11276
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 11530 of file z3py.py.

11530def LinearOrder(a, index):
11531 return FuncDeclRef(Z3_mk_linear_order(a.ctx_ref(), a.ast, index), a.ctx)
11532
11533
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 11480 of file z3py.py.

11480def Loop(re, lo, hi=0):
11481 """Create the regular expression accepting between a lower and upper bound repetitions
11482 >>> re = Loop(Re("a"), 1, 3)
11483 >>> print(simplify(InRe("aa", re)))
11484 True
11485 >>> print(simplify(InRe("aaaa", re)))
11486 False
11487 >>> print(simplify(InRe("", re)))
11488 False
11489 """
11490 if z3_debug():
11491 _z3_assert(is_expr(re), "expression expected")
11492 return ReRef(Z3_mk_re_loop(re.ctx_ref(), re.as_ast(), lo, hi), re.ctx)
11493
11494
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 4352 of file z3py.py.

4352def LShR(a, b):
4353 """Create the Z3 expression logical right shift.
4354
4355 Use the operator >> for the arithmetical right shift.
4356
4357 >>> x, y = BitVecs('x y', 32)
4358 >>> LShR(x, y)
4359 LShR(x, y)
4360 >>> (x >> y).sexpr()
4361 '(bvashr x y)'
4362 >>> LShR(x, y).sexpr()
4363 '(bvlshr x y)'
4364 >>> BitVecVal(4, 3)
4365 4
4366 >>> BitVecVal(4, 3).as_signed_long()
4367 -4
4368 >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
4369 -2
4370 >>> simplify(BitVecVal(4, 3) >> 1)
4371 6
4372 >>> simplify(LShR(BitVecVal(4, 3), 1))
4373 2
4374 >>> simplify(BitVecVal(2, 3) >> 1)
4375 1
4376 >>> simplify(LShR(BitVecVal(2, 3), 1))
4377 1
4378 """
4379 _check_bv_args(a, b)
4380 a, b = _coerce_exprs(a, b)
4381 return BitVecRef(Z3_mk_bvlshr(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4382
4383
Z3_ast Z3_API Z3_mk_bvlshr(Z3_context c, Z3_ast t1, Z3_ast t2)
Logical shift right.

◆ main_ctx()

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

239def main_ctx():
240 """Return a reference to the global Z3 context.
241
242 >>> x = Real('x')
243 >>> x.ctx == main_ctx()
244 True
245 >>> c = Context()
246 >>> c == main_ctx()
247 False
248 >>> x2 = Real('x', c)
249 >>> x2.ctx == c
250 True
251 >>> eq(x, x2)
252 False
253 """
254 global _main_ctx
255 if _main_ctx is None:
256 _main_ctx = Context()
257 return _main_ctx
258
259

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

4876def Map(f, *args):
4877 """Return a Z3 map array expression.
4878
4879 >>> f = Function('f', IntSort(), IntSort(), IntSort())
4880 >>> a1 = Array('a1', IntSort(), IntSort())
4881 >>> a2 = Array('a2', IntSort(), IntSort())
4882 >>> b = Map(f, a1, a2)
4883 >>> b
4884 Map(f, a1, a2)
4885 >>> prove(b[0] == f(a1[0], a2[0]))
4886 proved
4887 """
4888 args = _get_args(args)
4889 if z3_debug():
4890 _z3_assert(len(args) > 0, "At least one Z3 array expression expected")
4891 _z3_assert(is_func_decl(f), "First argument must be a Z3 function declaration")
4892 _z3_assert(all([is_array(a) for a in args]), "Z3 array expected expected")
4893 _z3_assert(len(args) == f.arity(), "Number of arguments mismatch")
4894 _args, sz = _to_ast_array(args)
4895 ctx = f.ctx
4896 return ArrayRef(Z3_mk_map(ctx.ref(), f.ast, sz, _args), ctx)
4897
4898
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 1881 of file z3py.py.

1881def mk_not(a):
1882 if is_not(a):
1883 return a.arg(0)
1884 else:
1885 return Not(a)
1886
1887

◆ Model()

Model ( ctx = None,
eval = {} )

Definition at line 6766 of file z3py.py.

6766def Model(ctx=None, eval = {}):
6767 ctx = _get_ctx(ctx)
6768 mdl = ModelRef(Z3_mk_model(ctx.ref()), ctx)
6769 for k, v in eval.items():
6770 mdl.update_value(k, v)
6771 return mdl
6772
6773
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 1998 of file z3py.py.

1998def MultiPattern(*args):
1999 """Create a Z3 multi-pattern using the given expressions `*args`
2000
2001 >>> f = Function('f', IntSort(), IntSort())
2002 >>> g = Function('g', IntSort(), IntSort())
2003 >>> x = Int('x')
2004 >>> q = ForAll(x, f(x) != g(x), patterns = [ MultiPattern(f(x), g(x)) ])
2005 >>> q
2006 ForAll(x, f(x) != g(x))
2007 >>> q.num_patterns()
2008 1
2009 >>> is_pattern(q.pattern(0))
2010 True
2011 >>> q.pattern(0)
2012 MultiPattern(f(Var(0)), g(Var(0)))
2013 """
2014 if z3_debug():
2015 _z3_assert(len(args) > 0, "At least one argument expected")
2016 _z3_assert(all([is_expr(a) for a in args]), "Z3 expressions expected")
2017 ctx = args[0].ctx
2018 args, sz = _to_ast_array(args)
2019 return PatternRef(Z3_mk_pattern(ctx.ref(), sz, args), ctx)
2020
2021
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 1862 of file z3py.py.

1862def Not(a, ctx=None):
1863 """Create a Z3 not expression or probe.
1864
1865 >>> p = Bool('p')
1866 >>> Not(Not(p))
1867 Not(Not(p))
1868 >>> simplify(Not(Not(p)))
1869 p
1870 """
1871 ctx = _get_ctx(_ctx_from_ast_arg_list([a], ctx))
1872 if is_probe(a):
1873 # Not is also used to build probes
1874 return Probe(Z3_probe_not(ctx.ref(), a.probe), ctx)
1875 else:
1876 s = BoolSort(ctx)
1877 a = s.cast(a)
1878 return BoolRef(Z3_mk_not(ctx.ref(), a.as_ast()), ctx)
1879
1880
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 11570 of file z3py.py.

11570def on_clause_eh(ctx, p, n, dep, clause):
11571 onc = _my_hacky_class
11572 p = _to_expr_ref(to_Ast(p), onc.ctx)
11573 clause = AstVector(to_AstVectorObj(clause), onc.ctx)
11574 deps = [dep[i] for i in range(n)]
11575 onc.on_clause(p, deps, clause)
11576

◆ open_log()

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

Definition at line 114 of file z3py.py.

114def open_log(fname):
115 """Log interaction to a file. This function must be invoked immediately after init(). """
116 Z3_open_log(fname)
117
118
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 11445 of file z3py.py.

11445def Option(re):
11446 """Create the regular expression that optionally accepts the argument.
11447 >>> re = Option(Re("a"))
11448 >>> print(simplify(InRe("a", re)))
11449 True
11450 >>> print(simplify(InRe("", re)))
11451 True
11452 >>> print(simplify(InRe("aa", re)))
11453 False
11454 """
11455 if z3_debug():
11456 _z3_assert(is_expr(re), "expression expected")
11457 return ReRef(Z3_mk_re_option(re.ctx_ref(), re.as_ast()), re.ctx)
11458
11459
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 1929 of file z3py.py.

1929def Or(*args):
1930 """Create a Z3 or-expression or or-probe.
1931
1932 >>> p, q, r = Bools('p q r')
1933 >>> Or(p, q, r)
1934 Or(p, q, r)
1935 >>> P = BoolVector('p', 5)
1936 >>> Or(P)
1937 Or(p__0, p__1, p__2, p__3, p__4)
1938 """
1939 last_arg = None
1940 if len(args) > 0:
1941 last_arg = args[len(args) - 1]
1942 if isinstance(last_arg, Context):
1943 ctx = args[len(args) - 1]
1944 args = args[:len(args) - 1]
1945 elif len(args) == 1 and isinstance(args[0], AstVector):
1946 ctx = args[0].ctx
1947 args = [a for a in args[0]]
1948 else:
1949 ctx = None
1950 args = _get_args(args)
1951 ctx = _get_ctx(_ctx_from_ast_arg_list(args, ctx))
1952 if z3_debug():
1953 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression or probe")
1954 if _has_probe(args):
1955 return _probe_or(args, ctx)
1956 else:
1957 args = _coerce_expr_list(args, ctx)
1958 _args, sz = _to_ast_array(args)
1959 return BoolRef(Z3_mk_or(ctx.ref(), sz, _args), ctx)
1960
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 8510 of file z3py.py.

8510def OrElse(*ts, **ks):
8511 """Return a tactic that applies the tactics in `*ts` until one of them succeeds (it doesn't fail).
8512
8513 >>> x = Int('x')
8514 >>> t = OrElse(Tactic('split-clause'), Tactic('skip'))
8515 >>> # Tactic split-clause fails if there is no clause in the given goal.
8516 >>> t(x == 0)
8517 [[x == 0]]
8518 >>> t(Or(x == 0, x == 1))
8519 [[x == 0], [x == 1]]
8520 """
8521 if z3_debug():
8522 _z3_assert(len(ts) >= 2, "At least two arguments expected")
8523 ctx = ks.get("ctx", None)
8524 num = len(ts)
8525 r = ts[0]
8526 for i in range(num - 1):
8527 r = _or_else(r, ts[i + 1], ctx)
8528 return r
8529
8530

◆ ParAndThen()

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

Definition at line 8566 of file z3py.py.

8566def ParAndThen(t1, t2, ctx=None):
8567 """Alias for ParThen(t1, t2, ctx)."""
8568 return ParThen(t1, t2, ctx)
8569
8570

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

8531def ParOr(*ts, **ks):
8532 """Return a tactic that applies the tactics in `*ts` in parallel until one of them succeeds (it doesn't fail).
8533
8534 >>> x = Int('x')
8535 >>> t = ParOr(Tactic('simplify'), Tactic('fail'))
8536 >>> t(x + 1 == 2)
8537 [[x == 1]]
8538 """
8539 if z3_debug():
8540 _z3_assert(len(ts) >= 2, "At least two arguments expected")
8541 ctx = _get_ctx(ks.get("ctx", None))
8542 ts = [_to_tactic(t, ctx) for t in ts]
8543 sz = len(ts)
8544 _args = (TacticObj * sz)()
8545 for i in range(sz):
8546 _args[i] = ts[i].tactic
8547 return Tactic(Z3_tactic_par_or(ctx.ref(), sz, _args), ctx)
8548
8549
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 9446 of file z3py.py.

9446def parse_smt2_file(f, sorts={}, decls={}, ctx=None):
9447 """Parse a file in SMT 2.0 format using the given sorts and decls.
9448
9449 This function is similar to parse_smt2_string().
9450 """
9451 ctx = _get_ctx(ctx)
9452 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
9453 dsz, dnames, ddecls = _dict2darray(decls, ctx)
9454 return AstVector(Z3_parse_smtlib2_file(ctx.ref(), f, ssz, snames, ssorts, dsz, dnames, ddecls), ctx)
9455
9456
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 9425 of file z3py.py.

9425def parse_smt2_string(s, sorts={}, decls={}, ctx=None):
9426 """Parse a string in SMT 2.0 format using the given sorts and decls.
9427
9428 The arguments sorts and decls are Python dictionaries used to initialize
9429 the symbol table used for the SMT 2.0 parser.
9430
9431 >>> parse_smt2_string('(declare-const x Int) (assert (> x 0)) (assert (< x 10))')
9432 [x > 0, x < 10]
9433 >>> x, y = Ints('x y')
9434 >>> f = Function('f', IntSort(), IntSort())
9435 >>> parse_smt2_string('(assert (> (+ foo (g bar)) 0))', decls={ 'foo' : x, 'bar' : y, 'g' : f})
9436 [x + f(y) > 0]
9437 >>> parse_smt2_string('(declare-const a U) (assert (> a 0))', sorts={ 'U' : IntSort() })
9438 [a > 0]
9439 """
9440 ctx = _get_ctx(ctx)
9441 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
9442 dsz, dnames, ddecls = _dict2darray(decls, ctx)
9443 return AstVector(Z3_parse_smtlib2_string(ctx.ref(), s, ssz, snames, ssorts, dsz, dnames, ddecls), ctx)
9444
9445
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 8550 of file z3py.py.

8550def ParThen(t1, t2, ctx=None):
8551 """Return a tactic that applies t1 and then t2 to every subgoal produced by t1.
8552 The subgoals are processed in parallel.
8553
8554 >>> x, y = Ints('x y')
8555 >>> t = ParThen(Tactic('split-clause'), Tactic('propagate-values'))
8556 >>> t(And(Or(x == 1, x == 2), y == x + 1))
8557 [[x == 1, y == 2], [x == 2, y == 3]]
8558 """
8559 t1 = _to_tactic(t1, ctx)
8560 t2 = _to_tactic(t2, ctx)
8561 if z3_debug():
8562 _z3_assert(t1.ctx == t2.ctx, "Context mismatch")
8563 return Tactic(Z3_tactic_par_and_then(t1.ctx.ref(), t1.tactic, t2.tactic), t1.ctx)
8564
8565
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 11526 of file z3py.py.

11526def PartialOrder(a, index):
11527 return FuncDeclRef(Z3_mk_partial_order(a.ctx_ref(), a.ast, index), a.ctx)
11528
11529
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 9202 of file z3py.py.

9202def PbEq(args, k, ctx=None):
9203 """Create a Pseudo-Boolean equality k constraint.
9204
9205 >>> a, b, c = Bools('a b c')
9206 >>> f = PbEq(((a,1),(b,3),(c,2)), 3)
9207 """
9208 _z3_check_cint_overflow(k, "k")
9209 ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
9210 return BoolRef(Z3_mk_pbeq(ctx.ref(), sz, _args, _coeffs, k), ctx)
9211
9212
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 9191 of file z3py.py.

9191def PbGe(args, k):
9192 """Create a Pseudo-Boolean inequality k constraint.
9193
9194 >>> a, b, c = Bools('a b c')
9195 >>> f = PbGe(((a,1),(b,3),(c,2)), 3)
9196 """
9197 _z3_check_cint_overflow(k, "k")
9198 ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
9199 return BoolRef(Z3_mk_pbge(ctx.ref(), sz, _args, _coeffs, k), ctx)
9200
9201
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 9180 of file z3py.py.

9180def PbLe(args, k):
9181 """Create a Pseudo-Boolean inequality k constraint.
9182
9183 >>> a, b, c = Bools('a b c')
9184 >>> f = PbLe(((a,1),(b,3),(c,2)), 3)
9185 """
9186 _z3_check_cint_overflow(k, "k")
9187 ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
9188 return BoolRef(Z3_mk_pble(ctx.ref(), sz, _args, _coeffs, k), ctx)
9189
9190
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 11538 of file z3py.py.

11538def PiecewiseLinearOrder(a, index):
11539 return FuncDeclRef(Z3_mk_piecewise_linear_order(a.ctx_ref(), a.ast, index), a.ctx)
11540
11541
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 11430 of file z3py.py.

11430def Plus(re):
11431 """Create the regular expression accepting one or more repetitions of argument.
11432 >>> re = Plus(Re("a"))
11433 >>> print(simplify(InRe("aa", re)))
11434 True
11435 >>> print(simplify(InRe("ab", re)))
11436 False
11437 >>> print(simplify(InRe("", re)))
11438 False
11439 """
11440 if z3_debug():
11441 _z3_assert(is_expr(re), "expression expected")
11442 return ReRef(Z3_mk_re_plus(re.ctx_ref(), re.as_ast()), re.ctx)
11443
11444
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 11175 of file z3py.py.

11175def PrefixOf(a, b):
11176 """Check if 'a' is a prefix of 'b'
11177 >>> s1 = PrefixOf("ab", "abc")
11178 >>> simplify(s1)
11179 True
11180 >>> s2 = PrefixOf("bc", "abc")
11181 >>> simplify(s2)
11182 False
11183 """
11184 ctx = _get_ctx2(a, b)
11185 a = _coerce_seq(a, ctx)
11186 b = _coerce_seq(b, ctx)
11187 return BoolRef(Z3_mk_seq_prefix(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
11188
11189
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 8846 of file z3py.py.

8846def probe_description(name, ctx=None):
8847 """Return a short description for the probe named `name`.
8848
8849 >>> d = probe_description('memory')
8850 """
8851 ctx = _get_ctx(ctx)
8852 return Z3_probe_get_descr(ctx.ref(), name)
8853
8854
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 8835 of file z3py.py.

8835def probes(ctx=None):
8836 """Return a list of all available probes in Z3.
8837
8838 >>> l = probes()
8839 >>> l.count('memory') == 1
8840 True
8841 """
8842 ctx = _get_ctx(ctx)
8843 return [Z3_get_probe_name(ctx.ref(), i) for i in range(Z3_get_num_probes(ctx.ref()))]
8844
8845
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 9087 of file z3py.py.

9087def Product(*args):
9088 """Create the product of the Z3 expressions.
9089
9090 >>> a, b, c = Ints('a b c')
9091 >>> Product(a, b, c)
9092 a*b*c
9093 >>> Product([a, b, c])
9094 a*b*c
9095 >>> A = IntVector('a', 5)
9096 >>> Product(A)
9097 a__0*a__1*a__2*a__3*a__4
9098 """
9099 args = _get_args(args)
9100 if len(args) == 0:
9101 return 1
9102 ctx = _ctx_from_ast_arg_list(args)
9103 if ctx is None:
9104 return _reduce(lambda a, b: a * b, args, 1)
9105 args = _coerce_expr_list(args, ctx)
9106 if is_bv(args[0]):
9107 return _reduce(lambda a, b: a * b, args, 1)
9108 else:
9109 _args, sz = _to_ast_array(args)
9110 return ArithRef(Z3_mk_mul(ctx.ref(), sz, _args), ctx)
9111
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 11724 of file z3py.py.

11724def PropagateFunction(name, *sig):
11725 """Create a function that gets tracked by user propagator.
11726 Every term headed by this function symbol is tracked.
11727 If a term is fixed and the fixed callback is registered a
11728 callback is invoked that the term headed by this function is fixed.
11729 """
11730 sig = _get_args(sig)
11731 if z3_debug():
11732 _z3_assert(len(sig) > 0, "At least two arguments expected")
11733 arity = len(sig) - 1
11734 rng = sig[arity]
11735 if z3_debug():
11736 _z3_assert(is_sort(rng), "Z3 sort expected")
11737 dom = (Sort * arity)()
11738 for i in range(arity):
11739 if z3_debug():
11740 _z3_assert(is_sort(sig[i]), "Z3 sort expected")
11741 dom[i] = sig[i].ast
11742 ctx = rng.ctx
11743 return FuncDeclRef(Z3_solver_propagate_declare(ctx.ref(), to_symbol(name, ctx), arity, dom, rng.ast), ctx)
11744
11745
11746
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 9274 of file z3py.py.

9274def prove(claim, show=False, **keywords):
9275 """Try to prove the given claim.
9276
9277 This is a simple function for creating demonstrations. It tries to prove
9278 `claim` by showing the negation is unsatisfiable.
9279
9280 >>> p, q = Bools('p q')
9281 >>> prove(Not(And(p, q)) == Or(Not(p), Not(q)))
9282 proved
9283 """
9284 if z3_debug():
9285 _z3_assert(is_bool(claim), "Z3 Boolean expression expected")
9286 s = Solver()
9287 s.set(**keywords)
9288 s.add(Not(claim))
9289 if show:
9290 print(s)
9291 r = s.check()
9292 if r == unsat:
9293 print("proved")
9294 elif r == unknown:
9295 print("failed to prove")
9296 print(s.model())
9297 else:
9298 print("counterexample")
9299 print(s.model())
9300
9301

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

3288def Q(a, b, ctx=None):
3289 """Return a Z3 rational a/b.
3290
3291 If `ctx=None`, then the global context is used.
3292
3293 >>> Q(3,5)
3294 3/5
3295 >>> Q(3,5).sort()
3296 Real
3297 """
3298 return simplify(RatVal(a, b, ctx=ctx))
3299
3300

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

11495def Range(lo, hi, ctx=None):
11496 """Create the range regular expression over two sequences of length 1
11497 >>> range = Range("a","z")
11498 >>> print(simplify(InRe("b", range)))
11499 True
11500 >>> print(simplify(InRe("bb", range)))
11501 False
11502 """
11503 lo = _coerce_seq(lo, ctx)
11504 hi = _coerce_seq(hi, ctx)
11505 if z3_debug():
11506 _z3_assert(is_expr(lo), "expression expected")
11507 _z3_assert(is_expr(hi), "expression expected")
11508 return ReRef(Z3_mk_re_range(lo.ctx_ref(), lo.ast, hi.ast), lo.ctx)
11509
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 3272 of file z3py.py.

3272def RatVal(a, b, ctx=None):
3273 """Return a Z3 rational a/b.
3274
3275 If `ctx=None`, then the global context is used.
3276
3277 >>> RatVal(3,5)
3278 3/5
3279 >>> RatVal(3,5).sort()
3280 Real
3281 """
3282 if z3_debug():
3283 _z3_assert(_is_int(a) or isinstance(a, str), "First argument cannot be converted into an integer")
3284 _z3_assert(_is_int(b) or isinstance(b, str), "Second argument cannot be converted into an integer")
3285 return simplify(RealVal(a, ctx) / RealVal(b, ctx))
3286
3287

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

11339def Re(s, ctx=None):
11340 """The regular expression that accepts sequence 's'
11341 >>> s1 = Re("ab")
11342 >>> s2 = Re(StringVal("ab"))
11343 >>> s3 = Re(Unit(BoolVal(True)))
11344 """
11345 s = _coerce_seq(s, ctx)
11346 return ReRef(Z3_mk_seq_to_re(s.ctx_ref(), s.as_ast()), s.ctx)
11347
11348
11349# Regular expressions
11350
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 3354 of file z3py.py.

3354def Real(name, ctx=None):
3355 """Return a real constant named `name`. If `ctx=None`, then the global context is used.
3356
3357 >>> x = Real('x')
3358 >>> is_real(x)
3359 True
3360 >>> is_real(x + 1)
3361 True
3362 """
3363 ctx = _get_ctx(ctx)
3364 return ArithRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), RealSort(ctx).ast), ctx)
3365
3366

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

3367def Reals(names, ctx=None):
3368 """Return a tuple of real constants.
3369
3370 >>> x, y, z = Reals('x y z')
3371 >>> Sum(x, y, z)
3372 x + y + z
3373 >>> Sum(x, y, z).sort()
3374 Real
3375 """
3376 ctx = _get_ctx(ctx)
3377 if isinstance(names, str):
3378 names = names.split(" ")
3379 return [Real(name, ctx) for name in names]
3380
3381

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

3212def RealSort(ctx=None):
3213 """Return the real sort in the given context. If `ctx=None`, then the global context is used.
3214
3215 >>> RealSort()
3216 Real
3217 >>> x = Const('x', RealSort())
3218 >>> is_real(x)
3219 True
3220 >>> is_int(x)
3221 False
3222 >>> x.sort() == RealSort()
3223 True
3224 """
3225 ctx = _get_ctx(ctx)
3226 return ArithSortRef(Z3_mk_real_sort(ctx.ref()), ctx)
3227
3228
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 3253 of file z3py.py.

3253def RealVal(val, ctx=None):
3254 """Return a Z3 real value.
3255
3256 `val` may be a Python int, long, float or string representing a number in decimal or rational notation.
3257 If `ctx=None`, then the global context is used.
3258
3259 >>> RealVal(1)
3260 1
3261 >>> RealVal(1).sort()
3262 Real
3263 >>> RealVal("3/5")
3264 3/5
3265 >>> RealVal("1.5")
3266 3/2
3267 """
3268 ctx = _get_ctx(ctx)
3269 return RatNumRef(Z3_mk_numeral(ctx.ref(), str(val), RealSort(ctx).ast), ctx)
3270
3271

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

◆ RealVar()

RealVar ( idx,
ctx = None )
Create a real free variable. Free variables are used to create quantified formulas.
They are also used to create polynomials.

>>> RealVar(0)
Var(0)

Definition at line 1510 of file z3py.py.

1510def RealVar(idx, ctx=None):
1511 """
1512 Create a real free variable. Free variables are used to create quantified formulas.
1513 They are also used to create polynomials.
1514
1515 >>> RealVar(0)
1516 Var(0)
1517 """
1518 return Var(idx, RealSort(ctx))
1519
1520

Referenced by RealVarVector().

◆ RealVarVector()

RealVarVector ( n,
ctx = None )
Create a list of Real free variables.
The variables have ids: 0, 1, ..., n-1

>>> x0, x1, x2, x3 = RealVarVector(4)
>>> x2
Var(2)

Definition at line 1521 of file z3py.py.

1521def RealVarVector(n, ctx=None):
1522 """
1523 Create a list of Real free variables.
1524 The variables have ids: 0, 1, ..., n-1
1525
1526 >>> x0, x1, x2, x3 = RealVarVector(4)
1527 >>> x2
1528 Var(2)
1529 """
1530 return [RealVar(i, ctx) for i in range(n)]
1531

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

3382def RealVector(prefix, sz, ctx=None):
3383 """Return a list of real constants of size `sz`.
3384
3385 >>> X = RealVector('x', 3)
3386 >>> X
3387 [x__0, x__1, x__2]
3388 >>> Sum(X)
3389 x__0 + x__1 + x__2
3390 >>> Sum(X).sort()
3391 Real
3392 """
3393 ctx = _get_ctx(ctx)
3394 return [Real("%s__%s" % (prefix, i), ctx) for i in range(sz)]
3395
3396

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

945def RecAddDefinition(f, args, body):
946 """Set the body of a recursive function.
947 Recursive definitions can be simplified if they are applied to ground
948 arguments.
949 >>> ctx = Context()
950 >>> fac = RecFunction('fac', IntSort(ctx), IntSort(ctx))
951 >>> n = Int('n', ctx)
952 >>> RecAddDefinition(fac, n, If(n == 0, 1, n*fac(n-1)))
953 >>> simplify(fac(5))
954 120
955 >>> s = Solver(ctx=ctx)
956 >>> s.add(fac(n) < 3)
957 >>> s.check()
958 sat
959 >>> s.model().eval(fac(5))
960 120
961 """
962 if is_app(args):
963 args = [args]
964 ctx = body.ctx
965 args = _get_args(args)
966 n = len(args)
967 _args = (Ast * n)()
968 for i in range(n):
969 _args[i] = args[i].ast
970 Z3_add_rec_def(ctx.ref(), f.ast, n, _args, body.ast)
971
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 927 of file z3py.py.

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

8599def Repeat(t, max=4294967295, ctx=None):
8600 """Return a tactic that keeps applying `t` until the goal is not modified anymore
8601 or the maximum number of iterations `max` is reached.
8602
8603 >>> x, y = Ints('x y')
8604 >>> c = And(Or(x == 0, x == 1), Or(y == 0, y == 1), x > y)
8605 >>> t = Repeat(OrElse(Tactic('split-clause'), Tactic('skip')))
8606 >>> r = t(c)
8607 >>> for subgoal in r: print(subgoal)
8608 [x == 0, y == 0, x > y]
8609 [x == 0, y == 1, x > y]
8610 [x == 1, y == 0, x > y]
8611 [x == 1, y == 1, x > y]
8612 >>> t = Then(t, Tactic('propagate-values'))
8613 >>> t(c)
8614 [[x == 1, y == 0]]
8615 """
8616 t = _to_tactic(t, ctx)
8617 return Tactic(Z3_tactic_repeat(t.ctx.ref(), t.tactic, max), t.ctx)
8618
8619
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 4474 of file z3py.py.

4474def RepeatBitVec(n, a):
4475 """Return an expression representing `n` copies of `a`.
4476
4477 >>> x = BitVec('x', 8)
4478 >>> n = RepeatBitVec(4, x)
4479 >>> n
4480 RepeatBitVec(4, x)
4481 >>> n.size()
4482 32
4483 >>> v0 = BitVecVal(10, 4)
4484 >>> print("%.x" % v0.as_long())
4485 a
4486 >>> v = simplify(RepeatBitVec(4, v0))
4487 >>> v.size()
4488 16
4489 >>> print("%.x" % v.as_long())
4490 aaaa
4491 """
4492 if z3_debug():
4493 _z3_assert(_is_int(n), "First argument must be an integer")
4494 _z3_assert(is_bv(a), "Second argument must be a Z3 bit-vector expression")
4495 return BitVecRef(Z3_mk_repeat(a.ctx_ref(), n, a.as_ast()), a.ctx)
4496
4497
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 11224 of file z3py.py.

11224def Replace(s, src, dst):
11225 """Replace the first occurrence of 'src' by 'dst' in 's'
11226 >>> r = Replace("aaa", "a", "b")
11227 >>> simplify(r)
11228 "baa"
11229 """
11230 ctx = _get_ctx2(dst, s)
11231 if ctx is None and is_expr(src):
11232 ctx = src.ctx
11233 src = _coerce_seq(src, ctx)
11234 dst = _coerce_seq(dst, ctx)
11235 s = _coerce_seq(s, ctx)
11236 return SeqRef(Z3_mk_seq_replace(src.ctx_ref(), s.as_ast(), src.as_ast(), dst.as_ast()), s.ctx)
11237
11238
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()

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

Definition at line 295 of file z3py.py.

295def reset_params():
296 """Reset all global (or module) parameters.
297 """
299
300
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 11358 of file z3py.py.

11358def ReSort(s):
11359 if is_ast(s):
11360 return ReSortRef(Z3_mk_re_sort(s.ctx.ref(), s.ast), s.ctx)
11361 if s is None or isinstance(s, Context):
11362 ctx = _get_ctx(s)
11363 return ReSortRef(Z3_mk_re_sort(ctx.ref(), Z3_mk_string_sort(ctx.ref())), s.ctx)
11364 raise Z3Exception("Regular expression sort constructor expects either a string or a context or no argument")
11365
11366
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 9861 of file z3py.py.

9861def RNA(ctx=None):
9862 ctx = _get_ctx(ctx)
9863 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_away(ctx.ref()), ctx)
9864
9865
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 9851 of file z3py.py.

9851def RNE(ctx=None):
9852 ctx = _get_ctx(ctx)
9853 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_even(ctx.ref()), ctx)
9854
9855
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 4384 of file z3py.py.

4384def RotateLeft(a, b):
4385 """Return an expression representing `a` rotated to the left `b` times.
4386
4387 >>> a, b = BitVecs('a b', 16)
4388 >>> RotateLeft(a, b)
4389 RotateLeft(a, b)
4390 >>> simplify(RotateLeft(a, 0))
4391 a
4392 >>> simplify(RotateLeft(a, 16))
4393 a
4394 """
4395 _check_bv_args(a, b)
4396 a, b = _coerce_exprs(a, b)
4397 return BitVecRef(Z3_mk_ext_rotate_left(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4398
4399
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 4400 of file z3py.py.

4400def RotateRight(a, b):
4401 """Return an expression representing `a` rotated to the right `b` times.
4402
4403 >>> a, b = BitVecs('a b', 16)
4404 >>> RotateRight(a, b)
4405 RotateRight(a, b)
4406 >>> simplify(RotateRight(a, 0))
4407 a
4408 >>> simplify(RotateRight(a, 16))
4409 a
4410 """
4411 _check_bv_args(a, b)
4412 a, b = _coerce_exprs(a, b)
4413 return BitVecRef(Z3_mk_ext_rotate_right(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4414
4415
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 9856 of file z3py.py.

9856def RoundNearestTiesToAway(ctx=None):
9857 ctx = _get_ctx(ctx)
9858 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_away(ctx.ref()), ctx)
9859
9860

◆ RoundNearestTiesToEven()

RoundNearestTiesToEven ( ctx = None)

Definition at line 9846 of file z3py.py.

9846def RoundNearestTiesToEven(ctx=None):
9847 ctx = _get_ctx(ctx)
9848 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_even(ctx.ref()), ctx)
9849
9850

◆ RoundTowardNegative()

RoundTowardNegative ( ctx = None)

Definition at line 9876 of file z3py.py.

9876def RoundTowardNegative(ctx=None):
9877 ctx = _get_ctx(ctx)
9878 return FPRMRef(Z3_mk_fpa_round_toward_negative(ctx.ref()), ctx)
9879
9880
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 9866 of file z3py.py.

9866def RoundTowardPositive(ctx=None):
9867 ctx = _get_ctx(ctx)
9868 return FPRMRef(Z3_mk_fpa_round_toward_positive(ctx.ref()), ctx)
9869
9870
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 9886 of file z3py.py.

9886def RoundTowardZero(ctx=None):
9887 ctx = _get_ctx(ctx)
9888 return FPRMRef(Z3_mk_fpa_round_toward_zero(ctx.ref()), ctx)
9889
9890
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 9881 of file z3py.py.

9881def RTN(ctx=None):
9882 ctx = _get_ctx(ctx)
9883 return FPRMRef(Z3_mk_fpa_round_toward_negative(ctx.ref()), ctx)
9884
9885

◆ RTP()

RTP ( ctx = None)

Definition at line 9871 of file z3py.py.

9871def RTP(ctx=None):
9872 ctx = _get_ctx(ctx)
9873 return FPRMRef(Z3_mk_fpa_round_toward_positive(ctx.ref()), ctx)
9874
9875

◆ RTZ()

RTZ ( ctx = None)

Definition at line 9891 of file z3py.py.

9891def RTZ(ctx=None):
9892 ctx = _get_ctx(ctx)
9893 return FPRMRef(Z3_mk_fpa_round_toward_zero(ctx.ref()), ctx)
9894
9895

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

4860def Select(a, *args):
4861 """Return a Z3 select array expression.
4862
4863 >>> a = Array('a', IntSort(), IntSort())
4864 >>> i = Int('i')
4865 >>> Select(a, i)
4866 a[i]
4867 >>> eq(Select(a, i), a[i])
4868 True
4869 """
4870 args = _get_args(args)
4871 if z3_debug():
4872 _z3_assert(is_array_sort(a), "First argument must be a Z3 array expression")
4873 return a[args]
4874
4875

◆ SeqFoldLeft()

SeqFoldLeft ( f,
a,
s )

Definition at line 11291 of file z3py.py.

11291def SeqFoldLeft(f, a, s):
11292 ctx = _get_ctx2(f, s)
11293 s = _coerce_seq(s, ctx)
11294 a = _py2expr(a)
11295 return _to_expr_ref(Z3_mk_seq_foldl(s.ctx_ref(), f.as_ast(), a.as_ast(), s.as_ast()), ctx)
11296
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 11297 of file z3py.py.

11297def SeqFoldLeftI(f, i, a, s):
11298 ctx = _get_ctx2(f, s)
11299 s = _coerce_seq(s, ctx)
11300 a = _py2expr(a)
11301 i = _py2epxr(i)
11302 return _to_expr_ref(Z3_mk_seq_foldli(s.ctx_ref(), f.as_ast(), i.as_ast(), a.as_ast(), s.as_ast()), ctx)
11303
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 11277 of file z3py.py.

11277def SeqMap(f, s):
11278 """Map function 'f' over sequence 's'"""
11279 ctx = _get_ctx2(f, s)
11280 s = _coerce_seq(s, ctx)
11281 return _to_expr_ref(Z3_mk_seq_map(s.ctx_ref(), f.as_ast(), s.as_ast()), ctx)
11282
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 11283 of file z3py.py.

11283def SeqMapI(f, i, s):
11284 """Map function 'f' over sequence 's' at index 'i'"""
11285 ctx = _get_ctx(f, s)
11286 s = _coerce_seq(s, ctx)
11287 if not is_expr(i):
11288 i = _py2expr(i)
11289 return _to_expr_ref(Z3_mk_seq_mapi(s.ctx_ref(), f.as_ast(), i.as_ast(), s.as_ast()), ctx)
11290
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 10945 of file z3py.py.

10945def SeqSort(s):
10946 """Create a sequence sort over elements provided in the argument
10947 >>> s = SeqSort(IntSort())
10948 >>> s == Unit(IntVal(1)).sort()
10949 True
10950 """
10951 return SeqSortRef(Z3_mk_seq_sort(s.ctx_ref(), s.ast), s.ctx)
10952
10953
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 9507 of file z3py.py.

9507def set_default_fp_sort(ebits, sbits, ctx=None):
9508 global _dflt_fpsort_ebits
9509 global _dflt_fpsort_sbits
9510 _dflt_fpsort_ebits = ebits
9511 _dflt_fpsort_sbits = sbits
9512
9513

◆ set_default_rounding_mode()

set_default_rounding_mode ( rm,
ctx = None )

Definition at line 9494 of file z3py.py.

9494def set_default_rounding_mode(rm, ctx=None):
9495 global _dflt_rounding_mode
9496 if is_fprm_value(rm):
9497 _dflt_rounding_mode = rm.kind()
9498 else:
9499 _z3_assert(_dflt_rounding_mode in _ROUNDING_MODES, "illegal rounding mode")
9500 _dflt_rounding_mode = rm
9501
9502

◆ set_option()

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

Definition at line 301 of file z3py.py.

301def set_option(*args, **kws):
302 """Alias for 'set_param' for backward compatibility.
303 """
304 return set_param(*args, **kws)
305
306

◆ set_param()

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

>>> set_param(precision=10)

Definition at line 271 of file z3py.py.

271def set_param(*args, **kws):
272 """Set Z3 global (or module) parameters.
273
274 >>> set_param(precision=10)
275 """
276 if z3_debug():
277 _z3_assert(len(args) % 2 == 0, "Argument list must have an even number of elements.")
278 new_kws = {}
279 for k in kws:
280 v = kws[k]
281 if not set_pp_option(k, v):
282 new_kws[k] = v
283 for key in new_kws:
284 value = new_kws[key]
285 Z3_global_param_set(str(key).upper(), _to_param_value(value))
286 prev = None
287 for a in args:
288 if prev is None:
289 prev = a
290 else:
291 Z3_global_param_set(str(prev), _to_param_value(a))
292 prev = None
293
294
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 5019 of file z3py.py.

5019def SetAdd(s, e):
5020 """ Add element e to set s
5021 >>> a = Const('a', SetSort(IntSort()))
5022 >>> SetAdd(a, 1)
5023 Store(a, 1, True)
5024 """
5025 ctx = _ctx_from_ast_arg_list([s, e])
5026 e = _py2expr(e, ctx)
5027 return ArrayRef(Z3_mk_set_add(ctx.ref(), s.as_ast(), e.as_ast()), ctx)
5028
5029
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 5041 of file z3py.py.

5041def SetComplement(s):
5042 """ The complement of set s
5043 >>> a = Const('a', SetSort(IntSort()))
5044 >>> SetComplement(a)
5045 complement(a)
5046 """
5047 ctx = s.ctx
5048 return ArrayRef(Z3_mk_set_complement(ctx.ref(), s.as_ast()), ctx)
5049
5050
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 5030 of file z3py.py.

5030def SetDel(s, e):
5031 """ Remove element e to set s
5032 >>> a = Const('a', SetSort(IntSort()))
5033 >>> SetDel(a, 1)
5034 Store(a, 1, False)
5035 """
5036 ctx = _ctx_from_ast_arg_list([s, e])
5037 e = _py2expr(e, ctx)
5038 return ArrayRef(Z3_mk_set_del(ctx.ref(), s.as_ast(), e.as_ast()), ctx)
5039
5040
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 5051 of file z3py.py.

5051def SetDifference(a, b):
5052 """ The set difference of a and b
5053 >>> a = Const('a', SetSort(IntSort()))
5054 >>> b = Const('b', SetSort(IntSort()))
5055 >>> SetDifference(a, b)
5056 setminus(a, b)
5057 """
5058 ctx = _ctx_from_ast_arg_list([a, b])
5059 return ArrayRef(Z3_mk_set_difference(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
5060
5061
Z3_ast Z3_API Z3_mk_set_difference(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Take the set difference between two sets.

◆ SetHasSize()

SetHasSize ( a,
k )

Definition at line 4933 of file z3py.py.

4933def SetHasSize(a, k):
4934 ctx = a.ctx
4935 k = _py2expr(k, ctx)
4936 return _to_expr_ref(Z3_mk_set_has_size(ctx.ref(), a.as_ast(), k.as_ast()), ctx)
4937
4938
Z3_ast Z3_API Z3_mk_set_has_size(Z3_context c, Z3_ast set, Z3_ast k)
Create predicate that holds if Boolean array set has k elements set to true.

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

5006def SetIntersect(*args):
5007 """ Take the union of sets
5008 >>> a = Const('a', SetSort(IntSort()))
5009 >>> b = Const('b', SetSort(IntSort()))
5010 >>> SetIntersect(a, b)
5011 intersection(a, b)
5012 """
5013 args = _get_args(args)
5014 ctx = _ctx_from_ast_arg_list(args)
5015 _args, sz = _to_ast_array(args)
5016 return ArrayRef(Z3_mk_set_intersect(ctx.ref(), sz, _args), ctx)
5017
5018
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 4970 of file z3py.py.

4970def SetSort(s):
4971 """ Create a set sort over element sort s"""
4972 return ArraySort(s, BoolSort())
4973
4974

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

4993def SetUnion(*args):
4994 """ Take the union of sets
4995 >>> a = Const('a', SetSort(IntSort()))
4996 >>> b = Const('b', SetSort(IntSort()))
4997 >>> SetUnion(a, b)
4998 union(a, b)
4999 """
5000 args = _get_args(args)
5001 ctx = _ctx_from_ast_arg_list(args)
5002 _args, sz = _to_ast_array(args)
5003 return ArrayRef(Z3_mk_set_union(ctx.ref(), sz, _args), ctx)
5004
5005
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 4416 of file z3py.py.

4416def SignExt(n, a):
4417 """Return a bit-vector expression with `n` extra sign-bits.
4418
4419 >>> x = BitVec('x', 16)
4420 >>> n = SignExt(8, x)
4421 >>> n.size()
4422 24
4423 >>> n
4424 SignExt(8, x)
4425 >>> n.sort()
4426 BitVec(24)
4427 >>> v0 = BitVecVal(2, 2)
4428 >>> v0
4429 2
4430 >>> v0.size()
4431 2
4432 >>> v = simplify(SignExt(6, v0))
4433 >>> v
4434 254
4435 >>> v.size()
4436 8
4437 >>> print("%.x" % v.as_long())
4438 fe
4439 """
4440 if z3_debug():
4441 _z3_assert(_is_int(n), "First argument must be an integer")
4442 _z3_assert(is_bv(a), "Second argument must be a Z3 bit-vector expression")
4443 return BitVecRef(Z3_mk_sign_ext(a.ctx_ref(), n, a.as_ast()), a.ctx)
4444
4445
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 7526 of file z3py.py.

7526def SimpleSolver(ctx=None, logFile=None):
7527 """Return a simple general purpose solver with limited amount of preprocessing.
7528
7529 >>> s = SimpleSolver()
7530 >>> x = Int('x')
7531 >>> s.add(x > 0)
7532 >>> s.check()
7533 sat
7534 """
7535 ctx = _get_ctx(ctx)
7536 return Solver(Z3_mk_simple_solver(ctx.ref()), ctx, logFile)
7537
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 8951 of file z3py.py.

8951def simplify(a, *arguments, **keywords):
8952 """Simplify the expression `a` using the given options.
8953
8954 This function has many options. Use `help_simplify` to obtain the complete list.
8955
8956 >>> x = Int('x')
8957 >>> y = Int('y')
8958 >>> simplify(x + 1 + y + x + 1)
8959 2 + 2*x + y
8960 >>> simplify((x + 1)*(y + 1), som=True)
8961 1 + x + y + x*y
8962 >>> simplify(Distinct(x, y, 1), blast_distinct=True)
8963 And(Not(x == y), Not(x == 1), Not(y == 1))
8964 >>> simplify(And(x == 0, y == 1), elim_and=True)
8965 Not(Or(Not(x == 0), Not(y == 1)))
8966 """
8967 if z3_debug():
8968 _z3_assert(is_expr(a), "Z3 expression expected")
8969 if len(arguments) > 0 or len(keywords) > 0:
8970 p = args2params(arguments, keywords, a.ctx)
8971 return _to_expr_ref(Z3_simplify_ex(a.ctx_ref(), a.as_ast(), p.params), a.ctx)
8972 else:
8973 return _to_expr_ref(Z3_simplify(a.ctx_ref(), a.as_ast()), a.ctx)
8974
8975
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 8981 of file z3py.py.

8981def simplify_param_descrs():
8982 """Return the set of parameter descriptions for Z3 `simplify` procedure."""
8983 return ParamDescrsRef(Z3_simplify_get_param_descrs(main_ctx().ref()), main_ctx())
8984
8985
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 9213 of file z3py.py.

9213def solve(*args, **keywords):
9214 """Solve the constraints `*args`.
9215
9216 This is a simple function for creating demonstrations. It creates a solver,
9217 configure it using the options in `keywords`, adds the constraints
9218 in `args`, and invokes check.
9219
9220 >>> a = Int('a')
9221 >>> solve(a > 0, a < 2)
9222 [a = 1]
9223 """
9224 show = keywords.pop("show", False)
9225 s = Solver()
9226 s.set(**keywords)
9227 s.add(*args)
9228 if show:
9229 print(s)
9230 r = s.check()
9231 if r == unsat:
9232 print("no solution")
9233 elif r == unknown:
9234 print("failed to solve")
9235 try:
9236 print(s.model())
9237 except Z3Exception:
9238 return
9239 else:
9240 print(s.model())
9241
9242

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

9243def solve_using(s, *args, **keywords):
9244 """Solve the constraints `*args` using solver `s`.
9245
9246 This is a simple function for creating demonstrations. It is similar to `solve`,
9247 but it uses the given solver `s`.
9248 It configures solver `s` using the options in `keywords`, adds the constraints
9249 in `args`, and invokes check.
9250 """
9251 show = keywords.pop("show", False)
9252 if z3_debug():
9253 _z3_assert(isinstance(s, Solver), "Solver object expected")
9254 s.set(**keywords)
9255 s.add(*args)
9256 if show:
9257 print("Problem:")
9258 print(s)
9259 r = s.check()
9260 if r == unsat:
9261 print("no solution")
9262 elif r == unknown:
9263 print("failed to solve")
9264 try:
9265 print(s.model())
9266 except Z3Exception:
9267 return
9268 else:
9269 if show:
9270 print("Solution:")
9271 print(s.model())
9272
9273

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

7505def SolverFor(logic, ctx=None, logFile=None):
7506 """Create a solver customized for the given logic.
7507
7508 The parameter `logic` is a string. It should be contains
7509 the name of a SMT-LIB logic.
7510 See http://www.smtlib.org/ for the name of all available logics.
7511
7512 >>> s = SolverFor("QF_LIA")
7513 >>> x = Int('x')
7514 >>> s.add(x > 0)
7515 >>> s.add(x < 2)
7516 >>> s.check()
7517 sat
7518 >>> s.model()
7519 [x = 1]
7520 """
7521 ctx = _get_ctx(ctx)
7522 logic = to_symbol(logic)
7523 return Solver(Z3_mk_solver_for_logic(ctx.ref(), logic), ctx, logFile)
7524
7525
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 3464 of file z3py.py.

3464def Sqrt(a, ctx=None):
3465 """ Return a Z3 expression which represents the square root of a.
3466
3467 >>> x = Real('x')
3468 >>> Sqrt(x)
3469 x**(1/2)
3470 """
3471 if not is_expr(a):
3472 ctx = _get_ctx(ctx)
3473 a = RealVal(a, ctx)
3474 return a ** "1/2"
3475
3476

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

4331def SRem(a, b):
4332 """Create the Z3 expression signed remainder.
4333
4334 Use the operator % for signed modulus, and URem() for unsigned remainder.
4335
4336 >>> x = BitVec('x', 32)
4337 >>> y = BitVec('y', 32)
4338 >>> SRem(x, y)
4339 SRem(x, y)
4340 >>> SRem(x, y).sort()
4341 BitVec(32)
4342 >>> (x % y).sexpr()
4343 '(bvsmod x y)'
4344 >>> SRem(x, y).sexpr()
4345 '(bvsrem x y)'
4346 """
4347 _check_bv_args(a, b)
4348 a, b = _coerce_exprs(a, b)
4349 return BitVecRef(Z3_mk_bvsrem(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4350
4351
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 11465 of file z3py.py.

11465def Star(re):
11466 """Create the regular expression accepting zero or more repetitions of argument.
11467 >>> re = Star(Re("a"))
11468 >>> print(simplify(InRe("aa", re)))
11469 True
11470 >>> print(simplify(InRe("ab", re)))
11471 False
11472 >>> print(simplify(InRe("", re)))
11473 True
11474 """
11475 if z3_debug():
11476 _z3_assert(is_expr(re), "expression expected")
11477 return ReRef(Z3_mk_re_star(re.ctx_ref(), re.as_ast()), re.ctx)
11478
11479
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 4843 of file z3py.py.

4843def Store(a, *args):
4844 """Return a Z3 store array expression.
4845
4846 >>> a = Array('a', IntSort(), IntSort())
4847 >>> i, v = Ints('i v')
4848 >>> s = Store(a, i, v)
4849 >>> s.sort()
4850 Array(Int, Int)
4851 >>> prove(s[i] == v)
4852 proved
4853 >>> j = Int('j')
4854 >>> prove(Implies(i != j, s[j] == a[j]))
4855 proved
4856 """
4857 return Update(a, args)
4858
4859

Referenced by ModelRef.get_interp().

◆ StrFromCode()

StrFromCode ( c)
Convert code to a string

Definition at line 11333 of file z3py.py.

11333def StrFromCode(c):
11334 """Convert code to a string"""
11335 if not is_expr(c):
11336 c = _py2expr(c)
11337 return SeqRef(Z3_mk_string_from_code(c.ctx_ref(), c.as_ast()), c.ctx)
11338
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 11108 of file z3py.py.

11108def String(name, ctx=None):
11109 """Return a string constant named `name`. If `ctx=None`, then the global context is used.
11110
11111 >>> x = String('x')
11112 """
11113 ctx = _get_ctx(ctx)
11114 return SeqRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), StringSort(ctx).ast), ctx)
11115
11116

◆ Strings()

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

Definition at line 11117 of file z3py.py.

11117def Strings(names, ctx=None):
11118 """Return a tuple of String constants. """
11119 ctx = _get_ctx(ctx)
11120 if isinstance(names, str):
11121 names = names.split(" ")
11122 return [String(name, ctx) for name in names]
11123
11124

◆ StringSort()

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

Definition at line 10926 of file z3py.py.

10926def StringSort(ctx=None):
10927 """Create a string sort
10928 >>> s = StringSort()
10929 >>> print(s)
10930 String
10931 """
10932 ctx = _get_ctx(ctx)
10933 return SeqSortRef(Z3_mk_string_sort(ctx.ref()), ctx)
10934

◆ StringVal()

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

Definition at line 11101 of file z3py.py.

11101def StringVal(s, ctx=None):
11102 """create a string expression"""
11103 s = "".join(str(ch) if 32 <= ord(ch) and ord(ch) < 127 else "\\u{%x}" % (ord(ch)) for ch in s)
11104 ctx = _get_ctx(ctx)
11105 return SeqRef(Z3_mk_string(ctx.ref(), s), ctx)
11106
11107
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 11327 of file z3py.py.

11327def StrToCode(s):
11328 """Convert a unit length string to integer code"""
11329 if not is_expr(s):
11330 s = _py2expr(s)
11331 return ArithRef(Z3_mk_string_to_code(s.ctx_ref(), s.as_ast()), s.ctx)
11332
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 11304 of file z3py.py.

11304def StrToInt(s):
11305 """Convert string expression to integer
11306 >>> a = StrToInt("1")
11307 >>> simplify(1 == a)
11308 True
11309 >>> b = StrToInt("2")
11310 >>> simplify(1 == b)
11311 False
11312 >>> c = StrToInt(IntToStr(2))
11313 >>> simplify(1 == c)
11314 False
11315 """
11316 s = _coerce_seq(s)
11317 return ArithRef(Z3_mk_str_to_int(s.ctx_ref(), s.as_ast()), s.ctx)
11318
11319
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

Definition at line 11130 of file z3py.py.

11130def SubSeq(s, offset, length):
11131 """Extract substring or subsequence starting at offset"""
11132 return Extract(s, offset, length)
11133
11134

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

8986def substitute(t, *m):
8987 """Apply substitution m on t, m is a list of pairs of the form (from, to).
8988 Every occurrence in t of from is replaced with to.
8989
8990 >>> x = Int('x')
8991 >>> y = Int('y')
8992 >>> substitute(x + 1, (x, y + 1))
8993 y + 1 + 1
8994 >>> f = Function('f', IntSort(), IntSort())
8995 >>> substitute(f(x) + f(y), (f(x), IntVal(1)), (f(y), IntVal(1)))
8996 1 + 1
8997 """
8998 if isinstance(m, tuple):
8999 m1 = _get_args(m)
9000 if isinstance(m1, list) and all(isinstance(p, tuple) for p in m1):
9001 m = m1
9002 if z3_debug():
9003 _z3_assert(is_expr(t), "Z3 expression expected")
9004 _z3_assert(
9005 all([isinstance(p, tuple) and is_expr(p[0]) and is_expr(p[1]) for p in m]),
9006 "Z3 invalid substitution, expression pairs expected.")
9007 _z3_assert(
9008 all([p[0].sort().eq(p[1].sort()) for p in m]),
9009 'Z3 invalid substitution, mismatching "from" and "to" sorts.')
9010 num = len(m)
9011 _from = (Ast * num)()
9012 _to = (Ast * num)()
9013 for i in range(num):
9014 _from[i] = m[i][0].as_ast()
9015 _to[i] = m[i][1].as_ast()
9016 return _to_expr_ref(Z3_substitute(t.ctx.ref(), t.as_ast(), num, _from, _to), t.ctx)
9017
9018
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 9039 of file z3py.py.

9039def substitute_funs(t, *m):
9040 """Apply substitution m on t, m is a list of pairs of a function and expression (from, to)
9041 Every occurrence in to of the function from is replaced with the expression to.
9042 The expression to can have free variables, that refer to the arguments of from.
9043 For examples, see
9044 """
9045 if isinstance(m, tuple):
9046 m1 = _get_args(m)
9047 if isinstance(m1, list) and all(isinstance(p, tuple) for p in m1):
9048 m = m1
9049 if z3_debug():
9050 _z3_assert(is_expr(t), "Z3 expression expected")
9051 _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.")
9052 num = len(m)
9053 _from = (FuncDecl * num)()
9054 _to = (Ast * num)()
9055 for i in range(num):
9056 _from[i] = m[i][0].as_func_decl()
9057 _to[i] = m[i][1].as_ast()
9058 return _to_expr_ref(Z3_substitute_funs(t.ctx.ref(), t.as_ast(), num, _from, _to), t.ctx)
9059
9060
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 9019 of file z3py.py.

9019def substitute_vars(t, *m):
9020 """Substitute the free variables in t with the expression in m.
9021
9022 >>> v0 = Var(0, IntSort())
9023 >>> v1 = Var(1, IntSort())
9024 >>> x = Int('x')
9025 >>> f = Function('f', IntSort(), IntSort(), IntSort())
9026 >>> # replace v0 with x+1 and v1 with x
9027 >>> substitute_vars(f(v0, v1), x + 1, x)
9028 f(x + 1, x)
9029 """
9030 if z3_debug():
9031 _z3_assert(is_expr(t), "Z3 expression expected")
9032 _z3_assert(all([is_expr(n) for n in m]), "Z3 invalid substitution, list of expressions expected.")
9033 num = len(m)
9034 _to = (Ast * num)()
9035 for i in range(num):
9036 _to[i] = m[i].as_ast()
9037 return _to_expr_ref(Z3_substitute_vars(t.ctx.ref(), t.as_ast(), num, _to), t.ctx)
9038
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

Definition at line 11125 of file z3py.py.

11125def SubString(s, offset, length):
11126 """Extract substring or subsequence starting at offset"""
11127 return Extract(s, offset, length)
11128
11129

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

11190def SuffixOf(a, b):
11191 """Check if 'a' is a suffix of 'b'
11192 >>> s1 = SuffixOf("ab", "abc")
11193 >>> simplify(s1)
11194 False
11195 >>> s2 = SuffixOf("bc", "abc")
11196 >>> simplify(s2)
11197 True
11198 """
11199 ctx = _get_ctx2(a, b)
11200 a = _coerce_seq(a, ctx)
11201 b = _coerce_seq(b, ctx)
11202 return BoolRef(Z3_mk_seq_suffix(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
11203
11204
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 9061 of file z3py.py.

9061def Sum(*args):
9062 """Create the sum of the Z3 expressions.
9063
9064 >>> a, b, c = Ints('a b c')
9065 >>> Sum(a, b, c)
9066 a + b + c
9067 >>> Sum([a, b, c])
9068 a + b + c
9069 >>> A = IntVector('a', 5)
9070 >>> Sum(A)
9071 a__0 + a__1 + a__2 + a__3 + a__4
9072 """
9073 args = _get_args(args)
9074 if len(args) == 0:
9075 return 0
9076 ctx = _ctx_from_ast_arg_list(args)
9077 if ctx is None:
9078 return _reduce(lambda a, b: a + b, args, 0)
9079 args = _coerce_expr_list(args, ctx)
9080 if is_bv(args[0]):
9081 return _reduce(lambda a, b: a + b, args, 0)
9082 else:
9083 _args, sz = _to_ast_array(args)
9084 return ArithRef(Z3_mk_add(ctx.ref(), sz, _args), ctx)
9085
9086
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 8640 of file z3py.py.

8640def tactic_description(name, ctx=None):
8641 """Return a short description for the tactic named `name`.
8642
8643 >>> d = tactic_description('simplify')
8644 """
8645 ctx = _get_ctx(ctx)
8646 return Z3_tactic_get_descr(ctx.ref(), name)
8647
8648
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 8629 of file z3py.py.

8629def tactics(ctx=None):
8630 """Return a list of all available tactics in Z3.
8631
8632 >>> l = tactics()
8633 >>> l.count('simplify') == 1
8634 True
8635 """
8636 ctx = _get_ctx(ctx)
8637 return [Z3_get_tactic_name(ctx.ref(), i) for i in range(Z3_get_num_tactics(ctx.ref()))]
8638
8639
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 8497 of file z3py.py.

8497def Then(*ts, **ks):
8498 """Return a tactic that applies the tactics in `*ts` in sequence. Shorthand for AndThen(*ts, **ks).
8499
8500 >>> x, y = Ints('x y')
8501 >>> t = Then(Tactic('simplify'), Tactic('solve-eqs'))
8502 >>> t(And(x == 0, y > x + 1))
8503 [[Not(y <= 1)]]
8504 >>> t(And(x == 0, y > x + 1)).as_expr()
8505 Not(y <= 1)
8506 """
8507 return AndThen(*ts, **ks)
8508
8509

◆ to_Ast()

to_Ast ( ptr)

Definition at line 11549 of file z3py.py.

11549def to_Ast(ptr,):
11550 ast = Ast(ptr)
11551 super(ctypes.c_void_p, ast).__init__(ptr)
11552 return ast
11553

◆ to_AstVectorObj()

to_AstVectorObj ( ptr)

Definition at line 11559 of file z3py.py.

11559def to_AstVectorObj(ptr,):
11560 v = AstVectorObj(ptr)
11561 super(ctypes.c_void_p, v).__init__(ptr)
11562 return v
11563
11564# NB. my-hacky-class only works for a single instance of OnClause
11565# it should be replaced with a proper correlation between OnClause
11566# and object references that can be passed over the FFI.
11567# for UserPropagator we use a global dictionary, which isn't great code.
11568

◆ to_ContextObj()

to_ContextObj ( ptr)

Definition at line 11554 of file z3py.py.

11554def to_ContextObj(ptr,):
11555 ctx = ContextObj(ptr)
11556 super(ctypes.c_void_p, ctx).__init__(ptr)
11557 return ctx
11558

◆ to_symbol()

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

Definition at line 124 of file z3py.py.

124def to_symbol(s, ctx=None):
125 """Convert an integer or string into a Z3 symbol."""
126 if _is_int(s):
127 return Z3_mk_int_symbol(_get_ctx(ctx).ref(), s)
128 else:
129 return Z3_mk_string_symbol(_get_ctx(ctx).ref(), s)
130
131
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 3429 of file z3py.py.

3429def ToInt(a):
3430 """ Return the Z3 expression ToInt(a).
3431
3432 >>> x = Real('x')
3433 >>> x.sort()
3434 Real
3435 >>> n = ToInt(x)
3436 >>> n
3437 ToInt(x)
3438 >>> n.sort()
3439 Int
3440 """
3441 if z3_debug():
3442 _z3_assert(a.is_real(), "Z3 real expression expected.")
3443 ctx = a.ctx
3444 return ArithRef(Z3_mk_real2int(ctx.ref(), a.as_ast()), ctx)
3445
3446
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 3411 of file z3py.py.

3411def ToReal(a):
3412 """ Return the Z3 expression ToReal(a).
3413
3414 >>> x = Int('x')
3415 >>> x.sort()
3416 Int
3417 >>> n = ToReal(x)
3418 >>> n
3419 ToReal(x)
3420 >>> n.sort()
3421 Real
3422 """
3423 if z3_debug():
3424 _z3_assert(a.is_int(), "Z3 integer expression expected.")
3425 ctx = a.ctx
3426 return ArithRef(Z3_mk_int2real(ctx.ref(), a.as_ast()), ctx)
3427
3428
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 11542 of file z3py.py.

11542def TransitiveClosure(f):
11543 """Given a binary relation R, such that the two arguments have the same sort
11544 create the transitive closure relation R+.
11545 The transitive closure R+ is a new relation.
11546 """
11547 return FuncDeclRef(Z3_mk_transitive_closure(f.ctx_ref(), f.ast), f.ctx)
11548
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 11534 of file z3py.py.

11534def TreeOrder(a, index):
11535 return FuncDeclRef(Z3_mk_tree_order(a.ctx_ref(), a.ast, index), a.ctx)
11536
11537
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 8620 of file z3py.py.

8620def TryFor(t, ms, ctx=None):
8621 """Return a tactic that applies `t` to a given goal for `ms` milliseconds.
8622
8623 If `t` does not terminate in `ms` milliseconds, then it fails.
8624 """
8625 t = _to_tactic(t, ctx)
8626 return Tactic(Z3_tactic_try_for(t.ctx.ref(), t.tactic, ms), t.ctx)
8627
8628
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 5416 of file z3py.py.

5416def TupleSort(name, sorts, ctx=None):
5417 """Create a named tuple sort base on a set of underlying sorts
5418 Example:
5419 >>> pair, mk_pair, (first, second) = TupleSort("pair", [IntSort(), StringSort()])
5420 """
5421 tuple = Datatype(name, ctx)
5422 projects = [("project%d" % i, sorts[i]) for i in range(len(sorts))]
5423 tuple.declare(name, *projects)
5424 tuple = tuple.create()
5425 return tuple, tuple.constructor(0), [tuple.accessor(0, i) for i in range(len(sorts))]
5426
5427

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

4289def UDiv(a, b):
4290 """Create the Z3 expression (unsigned) division `self / other`.
4291
4292 Use the operator / for signed division.
4293
4294 >>> x = BitVec('x', 32)
4295 >>> y = BitVec('y', 32)
4296 >>> UDiv(x, y)
4297 UDiv(x, y)
4298 >>> UDiv(x, y).sort()
4299 BitVec(32)
4300 >>> (x / y).sexpr()
4301 '(bvsdiv x y)'
4302 >>> UDiv(x, y).sexpr()
4303 '(bvudiv x y)'
4304 """
4305 _check_bv_args(a, b)
4306 a, b = _coerce_exprs(a, b)
4307 return BitVecRef(Z3_mk_bvudiv(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4308
4309
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 4253 of file z3py.py.

4253def UGE(a, b):
4254 """Create the Z3 expression (unsigned) `other >= self`.
4255
4256 Use the operator >= for signed greater than or equal to.
4257
4258 >>> x, y = BitVecs('x y', 32)
4259 >>> UGE(x, y)
4260 UGE(x, y)
4261 >>> (x >= y).sexpr()
4262 '(bvsge x y)'
4263 >>> UGE(x, y).sexpr()
4264 '(bvuge x y)'
4265 """
4266 _check_bv_args(a, b)
4267 a, b = _coerce_exprs(a, b)
4268 return BoolRef(Z3_mk_bvuge(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4269
4270
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 4271 of file z3py.py.

4271def UGT(a, b):
4272 """Create the Z3 expression (unsigned) `other > self`.
4273
4274 Use the operator > for signed greater than.
4275
4276 >>> x, y = BitVecs('x y', 32)
4277 >>> UGT(x, y)
4278 UGT(x, y)
4279 >>> (x > y).sexpr()
4280 '(bvsgt x y)'
4281 >>> UGT(x, y).sexpr()
4282 '(bvugt x y)'
4283 """
4284 _check_bv_args(a, b)
4285 a, b = _coerce_exprs(a, b)
4286 return BoolRef(Z3_mk_bvugt(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4287
4288
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 4217 of file z3py.py.

4217def ULE(a, b):
4218 """Create the Z3 expression (unsigned) `other <= self`.
4219
4220 Use the operator <= for signed less than or equal to.
4221
4222 >>> x, y = BitVecs('x y', 32)
4223 >>> ULE(x, y)
4224 ULE(x, y)
4225 >>> (x <= y).sexpr()
4226 '(bvsle x y)'
4227 >>> ULE(x, y).sexpr()
4228 '(bvule x y)'
4229 """
4230 _check_bv_args(a, b)
4231 a, b = _coerce_exprs(a, b)
4232 return BoolRef(Z3_mk_bvule(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4233
4234
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 4235 of file z3py.py.

4235def ULT(a, b):
4236 """Create the Z3 expression (unsigned) `other < self`.
4237
4238 Use the operator < for signed less than.
4239
4240 >>> x, y = BitVecs('x y', 32)
4241 >>> ULT(x, y)
4242 ULT(x, y)
4243 >>> (x < y).sexpr()
4244 '(bvslt x y)'
4245 >>> ULT(x, y).sexpr()
4246 '(bvult x y)'
4247 """
4248 _check_bv_args(a, b)
4249 a, b = _coerce_exprs(a, b)
4250 return BoolRef(Z3_mk_bvult(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4251
4252
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 11392 of file z3py.py.

11392def Union(*args):
11393 """Create union of regular expressions.
11394 >>> re = Union(Re("a"), Re("b"), Re("c"))
11395 >>> print (simplify(InRe("d", re)))
11396 False
11397 """
11398 args = _get_args(args)
11399 sz = len(args)
11400 if z3_debug():
11401 _z3_assert(sz > 0, "At least one argument expected.")
11402 _z3_assert(all([is_re(a) for a in args]), "All arguments must be regular expressions.")
11403 if sz == 1:
11404 return args[0]
11405 ctx = args[0].ctx
11406 v = (Ast * sz)()
11407 for i in range(sz):
11408 v[i] = args[i].as_ast()
11409 return ReRef(Z3_mk_re_union(ctx.ref(), sz, v), ctx)
11410
11411
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 11170 of file z3py.py.

11170def Unit(a):
11171 """Create a singleton sequence"""
11172 return SeqRef(Z3_mk_seq_unit(a.ctx_ref(), a.as_ast()), a.ctx)
11173
11174
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 4800 of file z3py.py.

4800def Update(a, *args):
4801 """Return a Z3 store array expression.
4802
4803 >>> a = Array('a', IntSort(), IntSort())
4804 >>> i, v = Ints('i v')
4805 >>> s = Update(a, i, v)
4806 >>> s.sort()
4807 Array(Int, Int)
4808 >>> prove(s[i] == v)
4809 proved
4810 >>> j = Int('j')
4811 >>> prove(Implies(i != j, s[j] == a[j]))
4812 proved
4813 """
4814 if z3_debug():
4815 _z3_assert(is_array_sort(a), "First argument must be a Z3 array expression")
4816 args = _get_args(args)
4817 ctx = a.ctx
4818 if len(args) <= 1:
4819 raise Z3Exception("array update requires index and value arguments")
4820 if len(args) == 2:
4821 i = args[0]
4822 v = args[1]
4823 i = a.sort().domain().cast(i)
4824 v = a.sort().range().cast(v)
4825 return _to_expr_ref(Z3_mk_store(ctx.ref(), a.as_ast(), i.as_ast(), v.as_ast()), ctx)
4826 v = a.sort().range().cast(args[-1])
4827 idxs = [a.sort().domain_n(i).cast(args[i]) for i in range(len(args)-1)]
4828 _args, sz = _to_ast_array(idxs)
4829 return _to_expr_ref(Z3_mk_store_n(ctx.ref(), a.as_ast(), sz, _args, v.as_ast()), ctx)
4830
4831
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 4310 of file z3py.py.

4310def URem(a, b):
4311 """Create the Z3 expression (unsigned) remainder `self % other`.
4312
4313 Use the operator % for signed modulus, and SRem() for signed remainder.
4314
4315 >>> x = BitVec('x', 32)
4316 >>> y = BitVec('y', 32)
4317 >>> URem(x, y)
4318 URem(x, y)
4319 >>> URem(x, y).sort()
4320 BitVec(32)
4321 >>> (x % y).sexpr()
4322 '(bvsmod x y)'
4323 >>> URem(x, y).sexpr()
4324 '(bvurem x y)'
4325 """
4326 _check_bv_args(a, b)
4327 a, b = _coerce_exprs(a, b)
4328 return BitVecRef(Z3_mk_bvurem(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4329
4330
Z3_ast Z3_API Z3_mk_bvurem(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned remainder.

◆ user_prop_created()

user_prop_created ( ctx,
cb,
id )

Definition at line 11670 of file z3py.py.

11670def user_prop_created(ctx, cb, id):
11671 prop = _prop_closures.get(ctx)
11672 old_cb = prop.cb
11673 prop.cb = cb
11674 id = _to_expr_ref(to_Ast(id), prop.ctx())
11675 prop.created(id)
11676 prop.cb = old_cb
11677
11678

◆ user_prop_decide()

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

Definition at line 11704 of file z3py.py.

11704def user_prop_decide(ctx, cb, t_ref, idx, phase):
11705 prop = _prop_closures.get(ctx)
11706 old_cb = prop.cb
11707 prop.cb = cb
11708 t = _to_expr_ref(to_Ast(t_ref), prop.ctx())
11709 prop.decide(t, idx, phase)
11710 prop.cb = old_cb
11711
11712

◆ user_prop_diseq()

user_prop_diseq ( ctx,
cb,
x,
y )

Definition at line 11695 of file z3py.py.

11695def user_prop_diseq(ctx, cb, x, y):
11696 prop = _prop_closures.get(ctx)
11697 old_cb = prop.cb
11698 prop.cb = cb
11699 x = _to_expr_ref(to_Ast(x), prop.ctx())
11700 y = _to_expr_ref(to_Ast(y), prop.ctx())
11701 prop.diseq(x, y)
11702 prop.cb = old_cb
11703

◆ user_prop_eq()

user_prop_eq ( ctx,
cb,
x,
y )

Definition at line 11686 of file z3py.py.

11686def user_prop_eq(ctx, cb, x, y):
11687 prop = _prop_closures.get(ctx)
11688 old_cb = prop.cb
11689 prop.cb = cb
11690 x = _to_expr_ref(to_Ast(x), prop.ctx())
11691 y = _to_expr_ref(to_Ast(y), prop.ctx())
11692 prop.eq(x, y)
11693 prop.cb = old_cb
11694

◆ user_prop_final()

user_prop_final ( ctx,
cb )

Definition at line 11679 of file z3py.py.

11679def user_prop_final(ctx, cb):
11680 prop = _prop_closures.get(ctx)
11681 old_cb = prop.cb
11682 prop.cb = cb
11683 prop.final()
11684 prop.cb = old_cb
11685

◆ user_prop_fixed()

user_prop_fixed ( ctx,
cb,
id,
value )

Definition at line 11661 of file z3py.py.

11661def user_prop_fixed(ctx, cb, id, value):
11662 prop = _prop_closures.get(ctx)
11663 old_cb = prop.cb
11664 prop.cb = cb
11665 id = _to_expr_ref(to_Ast(id), prop.ctx())
11666 value = _to_expr_ref(to_Ast(value), prop.ctx())
11667 prop.fixed(id, value)
11668 prop.cb = old_cb
11669

◆ user_prop_fresh()

user_prop_fresh ( ctx,
_new_ctx )

Definition at line 11647 of file z3py.py.

11647def user_prop_fresh(ctx, _new_ctx):
11648 _prop_closures.set_threaded()
11649 prop = _prop_closures.get(ctx)
11650 nctx = Context()
11651 Z3_del_context(nctx.ctx)
11652 new_ctx = to_ContextObj(_new_ctx)
11653 nctx.ctx = new_ctx
11654 nctx.eh = Z3_set_error_handler(new_ctx, z3_error_handler)
11655 nctx.owner = False
11656 new_prop = prop.fresh(nctx)
11657 _prop_closures.set(new_prop.id, new_prop)
11658 return new_prop.id
11659
11660
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 11641 of file z3py.py.

11641def user_prop_pop(ctx, cb, num_scopes):
11642 prop = _prop_closures.get(ctx)
11643 prop.cb = cb
11644 prop.pop(num_scopes)
11645
11646

◆ user_prop_push()

user_prop_push ( ctx,
cb )

Definition at line 11635 of file z3py.py.

11635def user_prop_push(ctx, cb):
11636 prop = _prop_closures.get(ctx)
11637 prop.cb = cb
11638 prop.push()
11639
11640

◆ Var()

Var ( idx,
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 1495 of file z3py.py.

1495def Var(idx, s):
1496 """Create a Z3 free variable. Free variables are used to create quantified formulas.
1497 A free variable with index n is bound when it occurs within the scope of n+1 quantified
1498 declarations.
1499
1500 >>> Var(0, IntSort())
1501 Var(0)
1502 >>> eq(Var(0, IntSort()), Var(0, BoolSort()))
1503 False
1504 """
1505 if z3_debug():
1506 _z3_assert(is_sort(s), "Z3 sort expected")
1507 return _to_expr_ref(Z3_mk_bound(s.ctx_ref(), idx, s.ast), s.ctx)
1508
1509
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 8914 of file z3py.py.

8914def When(p, t, ctx=None):
8915 """Return a tactic that applies tactic `t` only if probe `p` evaluates to true.
8916 Otherwise, it returns the input goal unmodified.
8917
8918 >>> t = When(Probe('size') > 2, Tactic('simplify'))
8919 >>> x, y = Ints('x y')
8920 >>> g = Goal()
8921 >>> g.add(x > 0)
8922 >>> g.add(y > 0)
8923 >>> t(g)
8924 [[x > 0, y > 0]]
8925 >>> g.add(x == y + 1)
8926 >>> t(g)
8927 [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
8928 """
8929 p = _to_probe(p, ctx)
8930 t = _to_tactic(t, ctx)
8931 return Tactic(Z3_tactic_when(t.ctx.ref(), p.probe, t.tactic), t.ctx)
8932
8933
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 8571 of file z3py.py.

8571def With(t, *args, **keys):
8572 """Return a tactic that applies tactic `t` using the given configuration options.
8573
8574 >>> x, y = Ints('x y')
8575 >>> t = With(Tactic('simplify'), som=True)
8576 >>> t((x + 1)*(y + 2) == 0)
8577 [[2*x + y + x*y == -2]]
8578 """
8579 ctx = keys.pop("ctx", None)
8580 t = _to_tactic(t, ctx)
8581 p = args2params(args, keys, t.ctx)
8582 return Tactic(Z3_tactic_using_params(t.ctx.ref(), t.tactic, p.params), t.ctx)
8583
8584
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 8585 of file z3py.py.

8585def WithParams(t, p):
8586 """Return a tactic that applies tactic `t` using the given configuration options.
8587
8588 >>> x, y = Ints('x y')
8589 >>> p = ParamsRef()
8590 >>> p.set("som", True)
8591 >>> t = WithParams(Tactic('simplify'), p)
8592 >>> t((x + 1)*(y + 2) == 0)
8593 [[2*x + y + x*y == -2]]
8594 """
8595 t = _to_tactic(t, None)
8596 return Tactic(Z3_tactic_using_params(t.ctx.ref(), t.tactic, p.params), t.ctx)
8597
8598

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

1846def Xor(a, b, ctx=None):
1847 """Create a Z3 Xor expression.
1848
1849 >>> p, q = Bools('p q')
1850 >>> Xor(p, q)
1851 Xor(p, q)
1852 >>> simplify(Xor(p, q))
1853 Not(p == q)
1854 """
1855 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1856 s = BoolSort(ctx)
1857 a = s.cast(a)
1858 b = s.cast(b)
1859 return BoolRef(Z3_mk_xor(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
1860
1861
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_error_handler()

z3_error_handler ( c,
e )

Definition at line 174 of file z3py.py.

174def z3_error_handler(c, e):
175 # Do nothing error handler, just avoid exit(0)
176 # The wrappers in z3core.py will raise a Z3Exception if an error is detected
177 return
178
179

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

4446def ZeroExt(n, a):
4447 """Return a bit-vector expression with `n` extra zero-bits.
4448
4449 >>> x = BitVec('x', 16)
4450 >>> n = ZeroExt(8, x)
4451 >>> n.size()
4452 24
4453 >>> n
4454 ZeroExt(8, x)
4455 >>> n.sort()
4456 BitVec(24)
4457 >>> v0 = BitVecVal(2, 2)
4458 >>> v0
4459 2
4460 >>> v0.size()
4461 2
4462 >>> v = simplify(ZeroExt(6, v0))
4463 >>> v
4464 2
4465 >>> v.size()
4466 8
4467 """
4468 if z3_debug():
4469 _z3_assert(_is_int(n), "First argument must be an integer")
4470 _z3_assert(is_bv(a), "Second argument must be a Z3 bit-vector expression")
4471 return BitVecRef(Z3_mk_zero_ext(a.ctx_ref(), n, a.as_ast()), a.ctx)
4472
4473
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 9466 of file z3py.py.

◆ _dflt_fpsort_sbits

int _dflt_fpsort_sbits = 53
protected

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

◆ _main_ctx

_main_ctx = None
protected

Definition at line 236 of file z3py.py.

◆ _my_hacky_class

_my_hacky_class = None
protected

Definition at line 11569 of file z3py.py.

◆ _on_clause_eh

_on_clause_eh = Z3_on_clause_eh(on_clause_eh)
protected

Definition at line 11577 of file z3py.py.

◆ _on_model_eh

_on_model_eh = on_model_eh_type(_global_on_model)
protected

Definition at line 7970 of file z3py.py.

◆ _on_models

dict _on_models = {}
protected

Definition at line 7962 of file z3py.py.

◆ _prop_closures

_prop_closures = None
protected

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

◆ _user_prop_created

_user_prop_created = Z3_created_eh(user_prop_created)
protected

Definition at line 11717 of file z3py.py.

◆ _user_prop_decide

_user_prop_decide = Z3_decide_eh(user_prop_decide)
protected

Definition at line 11721 of file z3py.py.

◆ _user_prop_diseq

_user_prop_diseq = Z3_eq_eh(user_prop_diseq)
protected

Definition at line 11720 of file z3py.py.

◆ _user_prop_eq

_user_prop_eq = Z3_eq_eh(user_prop_eq)
protected

Definition at line 11719 of file z3py.py.

◆ _user_prop_final

_user_prop_final = Z3_final_eh(user_prop_final)
protected

Definition at line 11718 of file z3py.py.

◆ _user_prop_fixed

_user_prop_fixed = Z3_fixed_eh(user_prop_fixed)
protected

Definition at line 11716 of file z3py.py.

◆ _user_prop_fresh

_user_prop_fresh = Z3_fresh_eh(user_prop_fresh)
protected

Definition at line 11715 of file z3py.py.

◆ _user_prop_pop

_user_prop_pop = Z3_pop_eh(user_prop_pop)
protected

Definition at line 11714 of file z3py.py.

◆ _user_prop_push

_user_prop_push = Z3_push_eh(user_prop_push)
protected

Definition at line 11713 of file z3py.py.

◆ sat

Definition at line 6972 of file z3py.py.

◆ unknown

Definition at line 6974 of file z3py.py.

◆ unsat

Definition at line 6973 of file z3py.py.

◆ Z3_DEBUG

Z3_DEBUG = __debug__

Definition at line 59 of file z3py.py.