Z3
Loading...
Searching...
No Matches
z3py Namespace Reference

Data Structures

class  Context
class  Z3PPObject
 ASTs base class. More...
class  AstRef
class  SortRef
class  TypeVarRef
class  FuncDeclRef
 Function Declarations. More...
class  ExprRef
 Expressions. More...
class  BoolSortRef
 Booleans. More...
class  BoolRef
class  PatternRef
 Patterns. More...
class  QuantifierRef
 Quantifiers. More...
class  ArithSortRef
 Arithmetic. More...
class  ArithRef
class  IntNumRef
class  RatNumRef
class  AlgebraicNumRef
class  BitVecSortRef
 Bit-Vectors. More...
class  BitVecRef
class  BitVecNumRef
class  ArraySortRef
 Arrays. More...
class  ArrayRef
class  FiniteSetSortRef
 Finite Sets. More...
class  FiniteSetRef
class  Datatype
class  ScopedConstructor
class  ScopedConstructorList
class  DatatypeSortRef
class  DatatypeRef
class  ParamsRef
 Parameter Sets. More...
class  ParamDescrsRef
class  Goal
class  AstVector
class  AstMap
class  FuncEntry
class  FuncInterp
class  ModelRef
class  Statistics
 Statistics. More...
class  CheckSatResult
class  Solver
class  Fixedpoint
 Fixedpoint. More...
class  FiniteDomainSortRef
class  FiniteDomainRef
class  FiniteDomainNumRef
class  OptimizeObjective
 Optimize. More...
class  Optimize
class  ApplyResult
class  Simplifier
class  Tactic
class  Probe
class  ParserContext
class  FPSortRef
class  FPRMSortRef
class  FPRef
class  FPRMRef
class  FPNumRef
class  SeqSortRef
 Strings, Sequences and Regular expressions. More...
class  CharSortRef
class  SeqRef
class  CharRef
class  ReSortRef
class  ReRef
class  OnClause
class  PropClosures
class  UserPropagateBase
class  FiniteFieldSortRef
class  FiniteFieldRef

Functions

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

Variables

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

Function Documentation

◆ _and_then()

_and_then ( t1,
t2,
ctx = None )
protected

Definition at line 9104 of file z3py.py.

9104def _and_then(t1, t2, ctx=None):
9105 t1 = _to_tactic(t1, ctx)
9106 t2 = _to_tactic(t2, ctx)
9107 if z3_debug():
9108 _z3_assert(t1.ctx == t2.ctx, "Context mismatch")
9109 return Tactic(Z3_tactic_and_then(t1.ctx.ref(), t1.tactic, t2.tactic), t1.ctx)
9110
9111
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 4837 of file z3py.py.

4837def _array_select(ar, arg):
4838 if isinstance(arg, tuple):
4839 args = [ar.sort().domain_n(i).cast(arg[i]) for i in range(len(arg))]
4840 _args, sz = _to_ast_array(args)
4841 return _to_expr_ref(Z3_mk_select_n(ar.ctx_ref(), ar.as_ast(), sz, _args), ar.ctx)
4842 arg = ar.sort().domain().cast(arg)
4843 return _to_expr_ref(Z3_mk_select(ar.ctx_ref(), ar.as_ast(), arg.as_ast()), ar.ctx)
4844
4845
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()

int _ast_kind ( Context ctx,
Any a )
protected

Definition at line 522 of file z3py.py.

522def _ast_kind(ctx : Context, a : Any) -> int:
523 if is_ast(a):
524 a = a.as_ast()
525 return Z3_get_ast_kind(ctx.ref(), a)
526
527
Z3_ast_kind Z3_API Z3_get_ast_kind(Z3_context c, Z3_ast a)
Return the kind of the given AST.

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

◆ _check_bv_args()

_check_bv_args ( a,
b )
protected

Definition at line 4359 of file z3py.py.

4359def _check_bv_args(a, b):
4360 if z3_debug():
4361 _z3_assert(is_bv(a) or is_bv(b), "First or second argument must be a Z3 bit-vector expression")
4362
4363

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

◆ _check_fp_args()

_check_fp_args ( a,
b )
protected

Definition at line 11248 of file z3py.py.

11248def _check_fp_args(a, b):
11249 if z3_debug():
11250 _z3_assert(is_fp(a) or is_fp(b), "First or second argument must be a Z3 floating-point expression")
11251
11252

◆ _check_same_sort()

_check_same_sort ( a,
b,
ctx = None )
protected

Definition at line 1299 of file z3py.py.

1299def _check_same_sort(a, b, ctx=None):
1300 if not isinstance(a, ExprRef):
1301 return False
1302 if not isinstance(b, ExprRef):
1303 return False
1304 if ctx is None:
1305 ctx = a.ctx
1306
1307 a_sort = Z3_get_sort(ctx.ctx, a.ast)
1308 b_sort = Z3_get_sort(ctx.ctx, b.ast)
1309 return Z3_is_eq_sort(ctx.ctx, a_sort, b_sort)
1310
1311
bool Z3_API Z3_is_eq_sort(Z3_context c, Z3_sort s1, Z3_sort s2)
compare sorts.
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.

Referenced by _coerce_exprs().

◆ _coerce_char()

_coerce_char ( ch,
ctx = None )
protected

Definition at line 11694 of file z3py.py.

11694def _coerce_char(ch, ctx=None):
11695 if isinstance(ch, str):
11696 ctx = _get_ctx(ctx)
11697 ch = CharVal(ch, ctx)
11698 if not is_expr(ch):
11699 raise Z3Exception("Character expression expected")
11700 return ch
11701

◆ _coerce_expr_list()

_coerce_expr_list ( alist,
ctx = None )
protected

Definition at line 1343 of file z3py.py.

1343def _coerce_expr_list(alist, ctx=None):
1344 has_expr = False
1345 for a in alist:
1346 if is_expr(a):
1347 has_expr = True
1348 break
1349 if not has_expr:
1350 alist = [_py2expr(a, ctx) for a in alist]
1351 s = _reduce(_coerce_expr_merge, alist, None)
1352 return [s.cast(a) for a in alist]
1353
1354

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

◆ _coerce_expr_merge()

_coerce_expr_merge ( s,
a )
protected

Definition at line 1281 of file z3py.py.

1281def _coerce_expr_merge(s, a):
1282 if is_expr(a):
1283 s1 = a.sort()
1284 if s is None:
1285 return s1
1286 if s1.eq(s):
1287 return s
1288 elif s.subsort(s1):
1289 return s1
1290 elif s1.subsort(s):
1291 return s
1292 else:
1293 if z3_debug():
1294 _z3_assert(s1.ctx == s.ctx, "context mismatch")
1295 _z3_assert(False, "sort mismatch")
1296 else:
1297 return s
1298

Referenced by _coerce_exprs().

◆ _coerce_exprs()

_coerce_exprs ( a,
b,
ctx = None )
protected

Definition at line 1312 of file z3py.py.

1312def _coerce_exprs(a, b, ctx=None):
1313 if not is_expr(a) and not is_expr(b):
1314 a = _py2expr(a, ctx)
1315 b = _py2expr(b, ctx)
1316 if isinstance(a, str) and isinstance(b, SeqRef):
1317 a = StringVal(a, b.ctx)
1318 if isinstance(b, str) and isinstance(a, SeqRef):
1319 b = StringVal(b, a.ctx)
1320 if isinstance(a, float) and isinstance(b, ArithRef):
1321 a = RealVal(a, b.ctx)
1322 if isinstance(b, float) and isinstance(a, ArithRef):
1323 b = RealVal(b, a.ctx)
1324
1325 if _check_same_sort(a, b, ctx):
1326 return (a, b)
1327
1328 s = None
1329 s = _coerce_expr_merge(s, a)
1330 s = _coerce_expr_merge(s, b)
1331 a = s.cast(a)
1332 b = s.cast(b)
1333 return (a, b)
1334
1335

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(), BvNand(), BvNor(), BVSDivNoOverflow(), BVSubNoOverflow(), BVSubNoUnderflow(), BvXnor(), 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 10165 of file z3py.py.

10165def _coerce_fp_expr_list(alist, ctx):
10166 first_fp_sort = None
10167 for a in alist:
10168 if is_fp(a):
10169 if first_fp_sort is None:
10170 first_fp_sort = a.sort()
10171 elif first_fp_sort == a.sort():
10172 pass # OK, same as before
10173 else:
10174 # we saw at least 2 different float sorts; something will
10175 # throw a sort mismatch later, for now assume None.
10176 first_fp_sort = None
10177 break
10178
10179 r = []
10180 for i in range(len(alist)):
10181 a = alist[i]
10182 is_repr = isinstance(a, str) and a.contains("2**(") and a.endswith(")")
10183 if is_repr or _is_int(a) or isinstance(a, (float, bool)):
10184 r.append(FPVal(a, None, first_fp_sort, ctx))
10185 else:
10186 r.append(a)
10187 return _coerce_expr_list(r, ctx)
10188
10189
10190# FP Sorts
10191

◆ _coerce_seq()

_coerce_seq ( s,
ctx = None )
protected

Definition at line 11744 of file z3py.py.

11744def _coerce_seq(s, ctx=None):
11745 if isinstance(s, str):
11746 ctx = _get_ctx(ctx)
11747 s = StringVal(s, ctx)
11748 if not is_expr(s):
11749 raise Z3Exception("Non-expression passed as a sequence")
11750 if not is_seq(s):
11751 raise Z3Exception("Non-sequence passed as a sequence")
11752 return s
11753
11754

Referenced by Concat().

◆ _ctx_from_ast_arg_list()

_ctx_from_ast_arg_list ( args,
default_ctx = None )
protected

Definition at line 528 of file z3py.py.

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

Referenced by _ctx_from_ast_args(), And(), Distinct(), FiniteSetDifference(), FiniteSetFilter(), FiniteSetIntersect(), FiniteSetMap(), FiniteSetMember(), FiniteSetRange(), FiniteSetSubset(), FiniteSetUnion(), If(), Implies(), IsMember(), IsSubset(), Not(), Or(), SetAdd(), SetDel(), SetDifference(), SetIntersect(), SetUnion(), and Xor().

◆ _ctx_from_ast_args()

_ctx_from_ast_args ( * args)
protected

Definition at line 542 of file z3py.py.

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

◆ _dflt_fps()

_dflt_fps ( ctx = None)
protected

Definition at line 10161 of file z3py.py.

10161def _dflt_fps(ctx=None):
10162 return get_default_fp_sort(ctx)
10163
10164

◆ _dflt_rm()

_dflt_rm ( ctx = None)
protected

Definition at line 10157 of file z3py.py.

10157def _dflt_rm(ctx=None):
10158 return get_default_rounding_mode(ctx)
10159
10160

◆ _dict2darray()

_dict2darray ( decls,
ctx )
protected

Definition at line 10030 of file z3py.py.

10030def _dict2darray(decls, ctx):
10031 sz = len(decls)
10032 _names = (Symbol * sz)()
10033 _decls = (FuncDecl * sz)()
10034 i = 0
10035 for k in decls:
10036 v = decls[k]
10037 if z3_debug():
10038 _z3_assert(isinstance(k, str), "String expected")
10039 _z3_assert(is_func_decl(v) or is_const(v), "Z3 declaration or constant expected")
10040 _names[i] = to_symbol(k, ctx)
10041 if is_const(v):
10042 _decls[i] = v.decl().ast
10043 else:
10044 _decls[i] = v.ast
10045 i = i + 1
10046 return sz, _names, _decls
10047

◆ _dict2sarray()

_dict2sarray ( sorts,
ctx )
protected

Definition at line 10014 of file z3py.py.

10014def _dict2sarray(sorts, ctx):
10015 sz = len(sorts)
10016 _names = (Symbol * sz)()
10017 _sorts = (Sort * sz)()
10018 i = 0
10019 for k in sorts:
10020 v = sorts[k]
10021 if z3_debug():
10022 _z3_assert(isinstance(k, str), "String expected")
10023 _z3_assert(is_sort(v), "Z3 sort expected")
10024 _names[i] = to_symbol(k, ctx)
10025 _sorts[i] = v.ast
10026 i = i + 1
10027 return sz, _names, _sorts
10028
10029

◆ _get_args()

_get_args ( args)
protected

Definition at line 152 of file z3py.py.

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

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

◆ _get_args_ast_list()

_get_args_ast_list ( args)
protected

Definition at line 168 of file z3py.py.

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

◆ _get_ctx()

Context _get_ctx ( ctx)
protected

Definition at line 287 of file z3py.py.

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

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

◆ _get_ctx2()

_get_ctx2 ( a,
b,
ctx = None )
protected

Definition at line 11755 of file z3py.py.

11755def _get_ctx2(a, b, ctx=None):
11756 if is_expr(a):
11757 return a.ctx
11758 if is_expr(b):
11759 return b.ctx
11760 if ctx is None:
11761 ctx = main_ctx()
11762 return ctx
11763
11764

◆ _global_on_model()

_global_on_model ( ctx)
protected

Definition at line 8575 of file z3py.py.

8575def _global_on_model(ctx):
8576 (fn, mdl) = _on_models[ctx]
8577 fn(mdl)
8578
8579

◆ _has_probe()

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

Definition at line 1984 of file z3py.py.

1984def _has_probe(args):
1985 """Return `True` if one of the elements of the given collection is a Z3 probe."""
1986 for arg in args:
1987 if is_probe(arg):
1988 return True
1989 return False
1990
1991

Referenced by And(), and Or().

◆ _is_algebraic()

_is_algebraic ( ctx,
a )
protected

Definition at line 2892 of file z3py.py.

2892def _is_algebraic(ctx, a):
2893 return Z3_is_algebraic_number(ctx.ref(), a)
2894
2895
bool Z3_API Z3_is_algebraic_number(Z3_context c, Z3_ast a)
Return true if the given AST is a real algebraic number.

Referenced by _to_expr_ref(), and is_algebraic_value().

◆ _is_int()

_is_int ( v)
protected

Definition at line 76 of file z3py.py.

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

Referenced by 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 2888 of file z3py.py.

2888def _is_numeral(ctx, a):
2889 return Z3_is_numeral_ast(ctx.ref(), a)
2890
2891
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 1541 of file z3py.py.

1541def _mk_bin(f, a, b):
1542 args = (Ast * 2)()
1543 if z3_debug():
1544 _z3_assert(a.ctx == b.ctx, "Context mismatch")
1545 args[0] = a.as_ast()
1546 args[1] = b.as_ast()
1547 return f(a.ctx.ref(), 2, args)
1548
1549

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

11036def _mk_fp_bin(f, rm, a, b, ctx):
11037 ctx = _get_ctx(ctx)
11038 [a, b] = _coerce_fp_expr_list([a, b], ctx)
11039 if z3_debug():
11040 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
11041 _z3_assert(is_fp(a) or is_fp(b), "Second or third argument must be a Z3 floating-point expression")
11042 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast()), ctx)
11043
11044

◆ _mk_fp_bin_norm()

_mk_fp_bin_norm ( f,
a,
b,
ctx )
protected

Definition at line 11045 of file z3py.py.

11045def _mk_fp_bin_norm(f, a, b, ctx):
11046 ctx = _get_ctx(ctx)
11047 [a, b] = _coerce_fp_expr_list([a, b], ctx)
11048 if z3_debug():
11049 _z3_assert(is_fp(a) or is_fp(b), "First or second argument must be a Z3 floating-point expression")
11050 return FPRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
11051
11052

◆ _mk_fp_bin_pred()

_mk_fp_bin_pred ( f,
a,
b,
ctx )
protected

Definition at line 11053 of file z3py.py.

11053def _mk_fp_bin_pred(f, a, b, ctx):
11054 ctx = _get_ctx(ctx)
11055 [a, b] = _coerce_fp_expr_list([a, b], ctx)
11056 if z3_debug():
11057 _z3_assert(is_fp(a) or is_fp(b), "First or second argument must be a Z3 floating-point expression")
11058 return BoolRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
11059
11060

◆ _mk_fp_tern()

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

Definition at line 11061 of file z3py.py.

11061def _mk_fp_tern(f, rm, a, b, c, ctx):
11062 ctx = _get_ctx(ctx)
11063 [a, b, c] = _coerce_fp_expr_list([a, b, c], ctx)
11064 if z3_debug():
11065 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
11066 _z3_assert(is_fp(a) or is_fp(b) or is_fp(
11067 c), "Second, third or fourth argument must be a Z3 floating-point expression")
11068 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
11069
11070

◆ _mk_fp_unary()

_mk_fp_unary ( f,
rm,
a,
ctx )
protected

Definition at line 11019 of file z3py.py.

11019def _mk_fp_unary(f, rm, a, ctx):
11020 ctx = _get_ctx(ctx)
11021 [a] = _coerce_fp_expr_list([a], ctx)
11022 if z3_debug():
11023 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
11024 _z3_assert(is_fp(a), "Second argument must be a Z3 floating-point expression")
11025 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast()), ctx)
11026
11027

◆ _mk_fp_unary_pred()

_mk_fp_unary_pred ( f,
a,
ctx )
protected

Definition at line 11028 of file z3py.py.

11028def _mk_fp_unary_pred(f, a, ctx):
11029 ctx = _get_ctx(ctx)
11030 [a] = _coerce_fp_expr_list([a], ctx)
11031 if z3_debug():
11032 _z3_assert(is_fp(a), "First argument must be a Z3 floating-point expression")
11033 return BoolRef(f(ctx.ref(), a.as_ast()), ctx)
11034
11035

◆ _mk_quantifier()

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

Definition at line 2340 of file z3py.py.

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

9112def _or_else(t1, t2, ctx=None):
9113 t1 = _to_tactic(t1, ctx)
9114 t2 = _to_tactic(t2, ctx)
9115 if z3_debug():
9116 _z3_assert(t1.ctx == t2.ctx, "Context mismatch")
9117 return Tactic(Z3_tactic_or_else(t1.ctx.ref(), t1.tactic, t2.tactic), t1.ctx)
9118
9119
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 9803 of file z3py.py.

9803def _pb_args_coeffs(args, default_ctx=None):
9804 args = _get_args_ast_list(args)
9805 if len(args) == 0:
9806 return _get_ctx(default_ctx), 0, (Ast * 0)(), (ctypes.c_int * 0)()
9807 args = [_reorder_pb_arg(arg) for arg in args]
9808 args, coeffs = zip(*args)
9809 if z3_debug():
9810 _z3_assert(len(args) > 0, "Non empty list of arguments expected")
9811 ctx = _ctx_from_ast_arg_list(args)
9812 if z3_debug():
9813 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
9814 args = _coerce_expr_list(args, ctx)
9815 _args, sz = _to_ast_array(args)
9816 _coeffs = (ctypes.c_int * len(coeffs))()
9817 for i in range(len(coeffs)):
9818 _z3_check_cint_overflow(coeffs[i], "coefficient")
9819 _coeffs[i] = coeffs[i]
9820 return ctx, sz, _args, _coeffs, args
9821
9822

◆ _probe_and()

_probe_and ( args,
ctx )
protected

Definition at line 9527 of file z3py.py.

9527def _probe_and(args, ctx):
9528 return _probe_nary(Z3_probe_and, args, ctx)
9529
9530

Referenced by And().

◆ _probe_nary()

_probe_nary ( f,
args,
ctx )
protected

Definition at line 9517 of file z3py.py.

9517def _probe_nary(f, args, ctx):
9518 if z3_debug():
9519 _z3_assert(len(args) > 0, "At least one argument expected")
9520 num = len(args)
9521 r = _to_probe(args[0], ctx)
9522 for i in range(num - 1):
9523 r = Probe(f(ctx.ref(), r.probe, _to_probe(args[i + 1], ctx).probe), ctx)
9524 return r
9525
9526

◆ _probe_or()

_probe_or ( args,
ctx )
protected

Definition at line 9531 of file z3py.py.

9531def _probe_or(args, ctx):
9532 return _probe_nary(Z3_probe_or, args, ctx)
9533
9534

Referenced by Or().

◆ _prove_html()

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

Definition at line 9994 of file z3py.py.

9994def _prove_html(claim, show=False, **keywords):
9995 """Version of function `prove` that renders HTML."""
9996 if z3_debug():
9997 _z3_assert(is_bool(claim), "Z3 Boolean expression expected")
9998 s = Solver()
9999 s.set(**keywords)
10000 s.add(Not(claim))
10001 if show:
10002 print(s)
10003 r = s.check()
10004 if r == unsat:
10005 print("<b>proved</b>")
10006 elif r == unknown:
10007 print("<b>failed to prove</b>")
10008 print(s.model())
10009 else:
10010 print("<b>counterexample</b>")
10011 print(s.model())
10012
10013

◆ _py2expr()

_py2expr ( a,
ctx = None )
protected

Definition at line 3293 of file z3py.py.

3293def _py2expr(a, ctx=None):
3294 if isinstance(a, bool):
3295 return BoolVal(a, ctx)
3296 if _is_int(a):
3297 return IntVal(a, ctx)
3298 if isinstance(a, float):
3299 return RealVal(a, ctx)
3300 if isinstance(a, str):
3301 return StringVal(a, ctx)
3302 if is_expr(a):
3303 return a
3304 if z3_debug():
3305 _z3_assert(False, "Python bool, int, long or float expected")
3306
3307

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

◆ _reduce()

_reduce ( func,
sequence,
initial )
protected

Definition at line 1336 of file z3py.py.

1336def _reduce(func, sequence, initial):
1337 result = initial
1338 for element in sequence:
1339 result = func(result, element)
1340 return result
1341
1342

Referenced by _coerce_expr_list().

◆ _reorder_pb_arg()

_reorder_pb_arg ( arg)
protected

Definition at line 9796 of file z3py.py.

9796def _reorder_pb_arg(arg):
9797 a, b = arg
9798 if not _is_int(b) and _is_int(a):
9799 return b, a
9800 return arg
9801
9802

◆ _solve_html()

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

Definition at line 9945 of file z3py.py.

9945def _solve_html(*args, **keywords):
9946 """Version of function `solve` that renders HTML output."""
9947 show = keywords.pop("show", False)
9948 s = Solver()
9949 s.set(**keywords)
9950 s.add(*args)
9951 if show:
9952 print("<b>Problem:</b>")
9953 print(s)
9954 r = s.check()
9955 if r == unsat:
9956 print("<b>no solution</b>")
9957 elif r == unknown:
9958 print("<b>failed to solve</b>")
9959 try:
9960 print(s.model())
9961 except Z3Exception:
9962 return
9963 else:
9964 if show:
9965 print("<b>Solution:</b>")
9966 print(s.model())
9967
9968

◆ _solve_using_html()

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

Definition at line 9969 of file z3py.py.

9969def _solve_using_html(s, *args, **keywords):
9970 """Version of function `solve_using` that renders HTML."""
9971 show = keywords.pop("show", False)
9972 if z3_debug():
9973 _z3_assert(isinstance(s, Solver), "Solver object expected")
9974 s.set(**keywords)
9975 s.add(*args)
9976 if show:
9977 print("<b>Problem:</b>")
9978 print(s)
9979 r = s.check()
9980 if r == unsat:
9981 print("<b>no solution</b>")
9982 elif r == unknown:
9983 print("<b>failed to solve</b>")
9984 try:
9985 print(s.model())
9986 except Z3Exception:
9987 return
9988 else:
9989 if show:
9990 print("<b>Solution:</b>")
9991 print(s.model())
9992
9993

◆ _sort()

SortRef _sort ( Context ctx,
Any a )
protected

Definition at line 730 of file z3py.py.

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

◆ _sort_kind()

_sort_kind ( ctx,
s )
protected

Sorts.

Definition at line 586 of file z3py.py.

586def _sort_kind(ctx, s):
587 return Z3_get_sort_kind(ctx.ref(), s)
588
589
Z3_sort_kind Z3_API Z3_get_sort_kind(Z3_context c, Z3_sort t)
Return the sort kind (e.g., array, tuple, int, bool, etc).

Referenced by _to_sort_ref().

◆ _symbol2py()

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

Definition at line 140 of file z3py.py.

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

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

◆ _to_ast_array()

_to_ast_array ( args)
protected

Definition at line 554 of file z3py.py.

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

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

◆ _to_ast_ref()

_to_ast_ref ( a,
ctx )
protected

Definition at line 570 of file z3py.py.

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

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

◆ _to_expr_ref()

_to_expr_ref ( a,
ctx )
protected

Definition at line 1225 of file z3py.py.

1225def _to_expr_ref(a, ctx):
1226 if isinstance(a, Pattern):
1227 return PatternRef(a, ctx)
1228 ctx_ref = ctx.ref()
1229 k = Z3_get_ast_kind(ctx_ref, a)
1230 if k == Z3_QUANTIFIER_AST:
1231 return QuantifierRef(a, ctx)
1232 # Check for finite set sort before checking sort kind
1233 s = Z3_get_sort(ctx_ref, a)
1234 if Z3_is_finite_set_sort(ctx_ref, s):
1235 return FiniteSetRef(a, ctx)
1236 sk = Z3_get_sort_kind(ctx_ref, s)
1237 if sk == Z3_BOOL_SORT:
1238 return BoolRef(a, ctx)
1239 if sk == Z3_INT_SORT:
1240 if k == Z3_NUMERAL_AST:
1241 return IntNumRef(a, ctx)
1242 return ArithRef(a, ctx)
1243 if sk == Z3_REAL_SORT:
1244 if k == Z3_NUMERAL_AST:
1245 return RatNumRef(a, ctx)
1246 if _is_algebraic(ctx, a):
1247 return AlgebraicNumRef(a, ctx)
1248 return ArithRef(a, ctx)
1249 if sk == Z3_BV_SORT:
1250 if k == Z3_NUMERAL_AST:
1251 return BitVecNumRef(a, ctx)
1252 else:
1253 return BitVecRef(a, ctx)
1254 if sk == Z3_ARRAY_SORT:
1255 return ArrayRef(a, ctx)
1256 if sk == Z3_DATATYPE_SORT:
1257 return DatatypeRef(a, ctx)
1258 if sk == Z3_FLOATING_POINT_SORT:
1259 if k == Z3_APP_AST and _is_numeral(ctx, a):
1260 return FPNumRef(a, ctx)
1261 else:
1262 return FPRef(a, ctx)
1263 if sk == Z3_FINITE_FIELD_SORT:
1264 return FiniteFieldRef(a, ctx)
1265 if sk == Z3_FINITE_DOMAIN_SORT:
1266 if k == Z3_NUMERAL_AST:
1267 return FiniteDomainNumRef(a, ctx)
1268 else:
1269 return FiniteDomainRef(a, ctx)
1270 if sk == Z3_ROUNDING_MODE_SORT:
1271 return FPRMRef(a, ctx)
1272 if sk == Z3_SEQ_SORT:
1273 return SeqRef(a, ctx)
1274 if sk == Z3_CHAR_SORT:
1275 return CharRef(a, ctx)
1276 if sk == Z3_RE_SORT:
1277 return ReRef(a, ctx)
1278 return ExprRef(a, ctx)
1279
1280
bool Z3_API Z3_is_finite_set_sort(Z3_context c, Z3_sort s)
Check if a sort is a finite set sort.

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

◆ _to_float_str()

_to_float_str ( val,
exp = 0 )
protected

Definition at line 10749 of file z3py.py.

10749def _to_float_str(val, exp=0):
10750 if isinstance(val, float):
10751 if math.isnan(val):
10752 res = "NaN"
10753 elif val == 0.0:
10754 sone = math.copysign(1.0, val)
10755 if sone < 0.0:
10756 return "-0.0"
10757 else:
10758 return "+0.0"
10759 elif val == float("+inf"):
10760 res = "+oo"
10761 elif val == float("-inf"):
10762 res = "-oo"
10763 else:
10764 v = val.as_integer_ratio()
10765 num = v[0]
10766 den = v[1]
10767 rvs = str(num) + "/" + str(den)
10768 res = rvs
10769 elif isinstance(val, bool):
10770 if val:
10771 res = "1.0"
10772 else:
10773 res = "0.0"
10774 elif _is_int(val):
10775 res = str(val)
10776 elif isinstance(val, str):
10777 inx = val.find("*(2**")
10778 if inx == -1:
10779 res = val
10780 if exp != 0:
10781 inx = val.lower().find("p")
10782 if inx != -1:
10783 res = val[:inx]
10784 exp = int(val[inx + 1:]) + int(exp)
10785 elif val[-1] == ")":
10786 res = val[0:inx]
10787 exp = str(int(val[inx + 5:-1]) + int(exp))
10788 else:
10789 _z3_assert(False, "String does not have floating-point numeral form.")
10790 elif z3_debug():
10791 _z3_assert(False, "Python value cannot be used to create floating-point numerals.")
10792 if exp == 0:
10793 return res
10794 else:
10795 return res + "p" + str(exp)
10796
10797

◆ _to_func_decl_array()

_to_func_decl_array ( args)
protected

Definition at line 546 of file z3py.py.

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

◆ _to_func_decl_ref()

_to_func_decl_ref ( a,
ctx )
protected

Definition at line 966 of file z3py.py.

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

Referenced by _to_ast_ref().

◆ _to_goal()

_to_goal ( a)
protected

Definition at line 9088 of file z3py.py.

9088def _to_goal(a):
9089 if isinstance(a, BoolRef):
9090 goal = Goal(ctx=a.ctx)
9091 goal.add(a)
9092 return goal
9093 else:
9094 return a
9095
9096

◆ _to_int_str()

_to_int_str ( val)
protected

Definition at line 3342 of file z3py.py.

3342def _to_int_str(val):
3343 if isinstance(val, float):
3344 return str(int(val))
3345 elif isinstance(val, bool):
3346 if val:
3347 return "1"
3348 else:
3349 return "0"
3350 else:
3351 return str(val)
3352
3353

Referenced by BitVecVal(), and IntVal().

◆ _to_param_value()

_to_param_value ( val)
protected

Definition at line 178 of file z3py.py.

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

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

◆ _to_pattern()

_to_pattern ( arg)
protected

Definition at line 2118 of file z3py.py.

2118def _to_pattern(arg):
2119 if is_pattern(arg):
2120 return arg
2121 else:
2122 return MultiPattern(arg)
2123

Referenced by _mk_quantifier().

◆ _to_probe()

_to_probe ( p,
ctx = None )
protected

Definition at line 9471 of file z3py.py.

9471def _to_probe(p, ctx=None):
9472 if is_probe(p):
9473 return p
9474 else:
9475 return Probe(p, ctx)
9476
9477

◆ _to_ref_array()

_to_ref_array ( ref,
args )
protected

Definition at line 562 of file z3py.py.

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

◆ _to_sort_ref()

_to_sort_ref ( s,
ctx )
protected

Definition at line 695 of file z3py.py.

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

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

9097def _to_tactic(t, ctx=None):
9098 if isinstance(t, Tactic):
9099 return t
9100 else:
9101 return Tactic(t, ctx)
9102
9103

◆ _valid_accessor()

_valid_accessor ( acc)
protected

Datatypes.

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

Definition at line 5525 of file z3py.py.

5525def _valid_accessor(acc):
5526 """Return `True` if acc is pair of the form (String, Datatype or Sort). """
5527 if not isinstance(acc, tuple):
5528 return False
5529 if len(acc) != 2:
5530 return False
5531 return isinstance(acc[0], str) and (isinstance(acc[1], Datatype) or is_sort(acc[1]))
5532
5533

Referenced by Datatype.declare_core().

◆ _z3_assert()

_z3_assert ( cond,
msg )
protected

Definition at line 113 of file z3py.py.

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

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

◆ _z3_check_cint_overflow()

_z3_check_cint_overflow ( n,
name )
protected

Definition at line 118 of file z3py.py.

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

◆ Abs()

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

Definition at line 9755 of file z3py.py.

9755def Abs(arg):
9756 """Create the absolute value of an arithmetic expression"""
9757 return If(arg > 0, arg, -arg)
9758
9759

Referenced by ArithRef.__abs__().

◆ AllChar()

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

Definition at line 12253 of file z3py.py.

12253def AllChar(regex_sort, ctx=None):
12254 """Create a regular expression that accepts all single character strings
12255 """
12256 return ReRef(Z3_mk_re_allchar(regex_sort.ctx_ref(), regex_sort.ast), regex_sort.ctx)
12257
12258# Special Relations
12259
12260
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 1992 of file z3py.py.

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

9120def AndThen(*ts, **ks):
9121 """Return a tactic that applies the tactics in `*ts` in sequence.
9122
9123 >>> x, y = Ints('x y')
9124 >>> t = AndThen(Tactic('simplify'), Tactic('solve-eqs'))
9125 >>> t(And(x == 0, y > x + 1))
9126 [[Not(y <= 1)]]
9127 >>> t(And(x == 0, y > x + 1)).as_expr()
9128 Not(y <= 1)
9129 """
9130 if z3_debug():
9131 _z3_assert(len(ts) >= 2, "At least two arguments expected")
9132 ctx = ks.get("ctx", None)
9133 num = len(ts)
9134 r = ts[0]
9135 for i in range(num - 1):
9136 r = _and_then(r, ts[i + 1], ctx)
9137 return r
9138
9139

◆ append_log()

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

Definition at line 127 of file z3py.py.

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

◆ args2params()

args2params ( arguments,
keywords,
ctx = None )
Convert python arguments into a Z3_params object.
A ':' is added to the keywords, and '_' is replaced with '-'

>>> args2params(['model', True, 'relevancy', 2], {'elim_and' : True})
(params model true relevancy 2 elim_and true)

Definition at line 6084 of file z3py.py.

6084def args2params(arguments, keywords, ctx=None):
6085 """Convert python arguments into a Z3_params object.
6086 A ':' is added to the keywords, and '_' is replaced with '-'
6087
6088 >>> args2params(['model', True, 'relevancy', 2], {'elim_and' : True})
6089 (params model true relevancy 2 elim_and true)
6090 """
6091 if z3_debug():
6092 _z3_assert(len(arguments) % 2 == 0, "Argument list must have an even number of elements.")
6093 prev = None
6094 r = ParamsRef(ctx)
6095 for a in arguments:
6096 if prev is None:
6097 prev = a
6098 else:
6099 r.set(prev, a)
6100 prev = None
6101 for k in keywords:
6102 v = keywords[k]
6103 r.set(k, v)
6104 return r
6105
6106

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

4974def Array(name, *sorts):
4975 """Return an array constant named `name` with the given domain and range sorts.
4976
4977 >>> a = Array('a', IntSort(), IntSort())
4978 >>> a.sort()
4979 Array(Int, Int)
4980 >>> a[0]
4981 a[0]
4982 """
4983 s = ArraySort(sorts)
4984 ctx = s.ctx
4985 return ArrayRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), s.ast), ctx)
4986
4987
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))
>>> ArraySort(IntSort(), BoolSort(), RealSort())
Array(Int, Bool, Real)

Definition at line 4939 of file z3py.py.

4939def ArraySort(*sig):
4940 """Return the Z3 array sort with the given domain and range sorts.
4941
4942 >>> A = ArraySort(IntSort(), BoolSort())
4943 >>> A
4944 Array(Int, Bool)
4945 >>> A.domain()
4946 Int
4947 >>> A.range()
4948 Bool
4949 >>> AA = ArraySort(IntSort(), A)
4950 >>> AA
4951 Array(Int, Array(Int, Bool))
4952 >>> ArraySort(IntSort(), BoolSort(), RealSort())
4953 Array(Int, Bool, Real)
4954 """
4955 sig = _get_args(sig)
4956 if z3_debug():
4957 _z3_assert(len(sig) > 1, "At least two arguments expected")
4958 arity = len(sig) - 1
4959 r = sig[arity]
4960 d = sig[0]
4961 if z3_debug():
4962 for s in sig:
4963 _z3_assert(is_sort(s), "Z3 sort expected")
4964 _z3_assert(s.ctx == r.ctx, "Context mismatch")
4965 ctx = d.ctx
4966 if len(sig) == 2:
4967 return ArraySortRef(Z3_mk_array_sort(ctx.ref(), d.ast, r.ast), ctx)
4968 dom = (Sort * arity)()
4969 for i in range(arity):
4970 dom[i] = sig[i].ast
4971 return ArraySortRef(Z3_mk_array_sort_n(ctx.ref(), arity, dom, r.ast), ctx)
4972
4973
Z3_sort Z3_API Z3_mk_array_sort_n(Z3_context c, unsigned n, Z3_sort const *domain, Z3_sort range)
Create an array type with N arguments.
Z3_sort Z3_API Z3_mk_array_sort(Z3_context c, Z3_sort domain, Z3_sort range)
Create an array type.

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

◆ AsArray()

AsArray ( f)
Return a Z3 as-array expression for the given function declaration.

>>> f = Function('f', IntSort(), IntSort())
>>> a = AsArray(f)
>>> a.sort()
Array(Int, Int)
>>> is_as_array(a)
True
>>> get_as_array_func(a) == f
True

Definition at line 5121 of file z3py.py.

5121def AsArray(f):
5122 """Return a Z3 as-array expression for the given function declaration.
5123
5124 >>> f = Function('f', IntSort(), IntSort())
5125 >>> a = AsArray(f)
5126 >>> a.sort()
5127 Array(Int, Int)
5128 >>> is_as_array(a)
5129 True
5130 >>> get_as_array_func(a) == f
5131 True
5132 """
5133 if z3_debug():
5134 _z3_assert(isinstance(f, FuncDeclRef), "function declaration expected")
5135 ctx = f.ctx
5136 return ArrayRef(Z3_mk_as_array(ctx.ref(), f.ast), ctx)
5137
5138
Z3_ast Z3_API Z3_mk_as_array(Z3_context c, Z3_func_decl f)
Create array with the same interpretation as a function. The array satisfies the property (f x) = (se...

Referenced by FiniteSetFilter(), and FiniteSetMap().

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

9778def AtLeast(*args):
9779 """Create an at-least Pseudo-Boolean k constraint.
9780
9781 >>> a, b, c = Bools('a b c')
9782 >>> f = AtLeast(a, b, c, 2)
9783 """
9784 args = _get_args(args)
9785 if z3_debug():
9786 _z3_assert(len(args) > 1, "Non empty list of arguments expected")
9787 ctx = _ctx_from_ast_arg_list(args)
9788 if z3_debug():
9789 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
9790 args1 = _coerce_expr_list(args[:-1], ctx)
9791 k = args[-1]
9792 _args, sz = _to_ast_array(args1)
9793 return BoolRef(Z3_mk_atleast(ctx.ref(), sz, _args, k), ctx)
9794
9795
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 9760 of file z3py.py.

9760def AtMost(*args):
9761 """Create an at-most Pseudo-Boolean k constraint.
9762
9763 >>> a, b, c = Bools('a b c')
9764 >>> f = AtMost(a, b, c, 2)
9765 """
9766 args = _get_args(args)
9767 if z3_debug():
9768 _z3_assert(len(args) > 1, "Non empty list of arguments expected")
9769 ctx = _ctx_from_ast_arg_list(args)
9770 if z3_debug():
9771 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
9772 args1 = _coerce_expr_list(args[:-1], ctx)
9773 k = args[-1]
9774 _args, sz = _to_ast_array(args1)
9775 return BoolRef(Z3_mk_atmost(ctx.ref(), sz, _args, k), ctx)
9776
9777
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 4214 of file z3py.py.

4214def BitVec(name, bv, ctx=None):
4215 """Return a bit-vector constant named `name`. `bv` may be the number of bits of a bit-vector sort.
4216 If `ctx=None`, then the global context is used.
4217
4218 >>> x = BitVec('x', 16)
4219 >>> is_bv(x)
4220 True
4221 >>> x.size()
4222 16
4223 >>> x.sort()
4224 BitVec(16)
4225 >>> word = BitVecSort(16)
4226 >>> x2 = BitVec('x', word)
4227 >>> eq(x, x2)
4228 True
4229 """
4230 if isinstance(bv, BitVecSortRef):
4231 ctx = bv.ctx
4232 else:
4233 ctx = _get_ctx(ctx)
4234 bv = BitVecSort(bv, ctx)
4235 return BitVecRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), bv.ast), ctx)
4236
4237

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

4238def BitVecs(names, bv, ctx=None):
4239 """Return a tuple of bit-vector constants of size bv.
4240
4241 >>> x, y, z = BitVecs('x y z', 16)
4242 >>> x.size()
4243 16
4244 >>> x.sort()
4245 BitVec(16)
4246 >>> Sum(x, y, z)
4247 0 + x + y + z
4248 >>> Product(x, y, z)
4249 1*x*y*z
4250 >>> simplify(Product(x, y, z))
4251 x*y*z
4252 """
4253 ctx = _get_ctx(ctx)
4254 if isinstance(names, str):
4255 names = names.split(" ")
4256 return [BitVec(name, bv, ctx) for name in names]
4257
4258

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

4182def BitVecSort(sz, ctx=None):
4183 """Return a Z3 bit-vector sort of the given size. If `ctx=None`, then the global context is used.
4184
4185 >>> Byte = BitVecSort(8)
4186 >>> Word = BitVecSort(16)
4187 >>> Byte
4188 BitVec(8)
4189 >>> x = Const('x', Byte)
4190 >>> eq(x, BitVec('x', 8))
4191 True
4192 """
4193 ctx = _get_ctx(ctx)
4194 return BitVecSortRef(Z3_mk_bv_sort(ctx.ref(), sz), ctx)
4195
4196
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 4197 of file z3py.py.

4197def BitVecVal(val, bv, ctx=None):
4198 """Return a bit-vector value with the given number of bits. If `ctx=None`, then the global context is used.
4199
4200 >>> v = BitVecVal(10, 32)
4201 >>> v
4202 10
4203 >>> print("0x%.8x" % v.as_long())
4204 0x0000000a
4205 """
4206 if is_bv_sort(bv):
4207 ctx = bv.ctx
4208 return BitVecNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), bv.ast), ctx)
4209 else:
4210 ctx = _get_ctx(ctx)
4211 return BitVecNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), BitVecSort(bv, ctx).ast), ctx)
4212
4213
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 1871 of file z3py.py.

1871def Bool(name, ctx=None):
1872 """Return a Boolean constant named `name`. If `ctx=None`, then the global context is used.
1873
1874 >>> p = Bool('p')
1875 >>> q = Bool('q')
1876 >>> And(p, q)
1877 And(p, q)
1878 """
1879 ctx = _get_ctx(ctx)
1880 return BoolRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), BoolSort(ctx).ast), ctx)
1881
1882

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

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

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

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

1852def BoolVal(val, ctx=None):
1853 """Return the Boolean value `True` or `False`. If `ctx=None`, then the global context is used.
1854
1855 >>> BoolVal(True)
1856 True
1857 >>> is_true(BoolVal(True))
1858 True
1859 >>> is_true(True)
1860 False
1861 >>> is_false(BoolVal(False))
1862 True
1863 """
1864 ctx = _get_ctx(ctx)
1865 if val:
1866 return BoolRef(Z3_mk_true(ctx.ref()), ctx)
1867 else:
1868 return BoolRef(Z3_mk_false(ctx.ref()), ctx)
1869
1870
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 1899 of file z3py.py.

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

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

4150def BV2Int(a, is_signed=False):
4151 """Return the Z3 expression BV2Int(a).
4152
4153 >>> b = BitVec('b', 3)
4154 >>> BV2Int(b).sort()
4155 Int
4156 >>> x = Int('x')
4157 >>> x > BV2Int(b)
4158 x > BV2Int(b)
4159 >>> x > BV2Int(b, is_signed=False)
4160 x > BV2Int(b)
4161 >>> x > BV2Int(b, is_signed=True)
4162 x > If(b < 0, BV2Int(b) - 8, BV2Int(b))
4163 >>> solve(x > BV2Int(b), b == 1, x < 3)
4164 [x = 2, b = 1]
4165 """
4166 if z3_debug():
4167 _z3_assert(is_bv(a), "First argument must be a Z3 bit-vector expression")
4168 ctx = a.ctx
4169 # investigate problem with bv2int
4170 return ArithRef(Z3_mk_bv2int(ctx.ref(), a.as_ast(), is_signed), ctx)
4171
4172
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 4698 of file z3py.py.

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

4705def BVAddNoUnderflow(a, b):
4706 """A predicate the determines that signed bit-vector addition does not underflow"""
4707 _check_bv_args(a, b)
4708 a, b = _coerce_exprs(a, b)
4709 return BoolRef(Z3_mk_bvadd_no_underflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4710
4711
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 4740 of file z3py.py.

4740def BVMulNoOverflow(a, b, signed):
4741 """A predicate the determines that bit-vector multiplication does not overflow"""
4742 _check_bv_args(a, b)
4743 a, b = _coerce_exprs(a, b)
4744 return BoolRef(Z3_mk_bvmul_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast(), signed), a.ctx)
4745
4746
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 4747 of file z3py.py.

4747def BVMulNoUnderflow(a, b):
4748 """A predicate the determines that bit-vector signed multiplication does not underflow"""
4749 _check_bv_args(a, b)
4750 a, b = _coerce_exprs(a, b)
4751 return BoolRef(Z3_mk_bvmul_no_underflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4752
4753
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...

◆ BvNand()

BvNand ( a,
b )
Return the bitwise NAND of `a` and `b`.

>>> x = BitVec('x', 8)
>>> y = BitVec('y', 8)
>>> BvNand(x, y)
bvnand(x, y)

Definition at line 4659 of file z3py.py.

4659def BvNand(a, b):
4660 """Return the bitwise NAND of `a` and `b`.
4661
4662 >>> x = BitVec('x', 8)
4663 >>> y = BitVec('y', 8)
4664 >>> BvNand(x, y)
4665 bvnand(x, y)
4666 """
4667 _check_bv_args(a, b)
4668 a, b = _coerce_exprs(a, b)
4669 return BitVecRef(Z3_mk_bvnand(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4670
4671
Z3_ast Z3_API Z3_mk_bvnand(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise nand.

◆ BvNor()

BvNor ( a,
b )
Return the bitwise NOR of `a` and `b`.

>>> x = BitVec('x', 8)
>>> y = BitVec('y', 8)
>>> BvNor(x, y)
bvnor(x, y)

Definition at line 4672 of file z3py.py.

4672def BvNor(a, b):
4673 """Return the bitwise NOR of `a` and `b`.
4674
4675 >>> x = BitVec('x', 8)
4676 >>> y = BitVec('y', 8)
4677 >>> BvNor(x, y)
4678 bvnor(x, y)
4679 """
4680 _check_bv_args(a, b)
4681 a, b = _coerce_exprs(a, b)
4682 return BitVecRef(Z3_mk_bvnor(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4683
4684
Z3_ast Z3_API Z3_mk_bvnor(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise nor.

◆ BVRedAnd()

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

Definition at line 4645 of file z3py.py.

4645def BVRedAnd(a):
4646 """Return the reduction-and expression of `a`."""
4647 if z3_debug():
4648 _z3_assert(is_bv(a), "First argument must be a Z3 bit-vector expression")
4649 return BitVecRef(Z3_mk_bvredand(a.ctx_ref(), a.as_ast()), a.ctx)
4650
4651
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 4652 of file z3py.py.

4652def BVRedOr(a):
4653 """Return the reduction-or expression of `a`."""
4654 if z3_debug():
4655 _z3_assert(is_bv(a), "First argument must be a Z3 bit-vector expression")
4656 return BitVecRef(Z3_mk_bvredor(a.ctx_ref(), a.as_ast()), a.ctx)
4657
4658
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 4726 of file z3py.py.

4726def BVSDivNoOverflow(a, b):
4727 """A predicate the determines that bit-vector signed division does not overflow"""
4728 _check_bv_args(a, b)
4729 a, b = _coerce_exprs(a, b)
4730 return BoolRef(Z3_mk_bvsdiv_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4731
4732
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 4733 of file z3py.py.

4733def BVSNegNoOverflow(a):
4734 """A predicate the determines that bit-vector unary negation does not overflow"""
4735 if z3_debug():
4736 _z3_assert(is_bv(a), "First argument must be a Z3 bit-vector expression")
4737 return BoolRef(Z3_mk_bvneg_no_overflow(a.ctx_ref(), a.as_ast()), a.ctx)
4738
4739
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 4712 of file z3py.py.

4712def BVSubNoOverflow(a, b):
4713 """A predicate the determines that bit-vector subtraction does not overflow"""
4714 _check_bv_args(a, b)
4715 a, b = _coerce_exprs(a, b)
4716 return BoolRef(Z3_mk_bvsub_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4717
4718
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 4719 of file z3py.py.

4719def BVSubNoUnderflow(a, b, signed):
4720 """A predicate the determines that bit-vector subtraction does not underflow"""
4721 _check_bv_args(a, b)
4722 a, b = _coerce_exprs(a, b)
4723 return BoolRef(Z3_mk_bvsub_no_underflow(a.ctx_ref(), a.as_ast(), b.as_ast(), signed), a.ctx)
4724
4725
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.

◆ BvXnor()

BvXnor ( a,
b )
Return the bitwise XNOR of `a` and `b`.

>>> x = BitVec('x', 8)
>>> y = BitVec('y', 8)
>>> BvXnor(x, y)
bvxnor(x, y)

Definition at line 4685 of file z3py.py.

4685def BvXnor(a, b):
4686 """Return the bitwise XNOR of `a` and `b`.
4687
4688 >>> x = BitVec('x', 8)
4689 >>> y = BitVec('y', 8)
4690 >>> BvXnor(x, y)
4691 bvxnor(x, y)
4692 """
4693 _check_bv_args(a, b)
4694 a, b = _coerce_exprs(a, b)
4695 return BitVecRef(Z3_mk_bvxnor(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4696
4697
Z3_ast Z3_API Z3_mk_bvxnor(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise xnor.

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

3596def Cbrt(a, ctx=None):
3597 """ Return a Z3 expression which represents the cubic root of a.
3598
3599 >>> x = Real('x')
3600 >>> Cbrt(x)
3601 x**(1/3)
3602 """
3603 if not is_expr(a):
3604 ctx = _get_ctx(ctx)
3605 a = RealVal(a, ctx)
3606 return a ** "1/3"
3607

◆ CharFromBv()

CharFromBv ( bv)

Definition at line 11727 of file z3py.py.

11727def CharFromBv(bv):
11728 if not is_expr(bv):
11729 raise Z3Exception("Bit-vector expression needed")
11730 return _to_expr_ref(Z3_mk_char_from_bv(bv.ctx_ref(), bv.as_ast()), bv.ctx)
11731
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 11740 of file z3py.py.

11740def CharIsDigit(ch, ctx=None):
11741 ch = _coerce_char(ch, ctx)
11742 return ch.is_digit()
11743

◆ CharSort()

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

Definition at line 11620 of file z3py.py.

11620def CharSort(ctx=None):
11621 """Create a character sort
11622 >>> ch = CharSort()
11623 >>> print(ch)
11624 Char
11625 """
11626 ctx = _get_ctx(ctx)
11627 return CharSortRef(Z3_mk_char_sort(ctx.ref()), ctx)
11628
11629
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 11732 of file z3py.py.

11732def CharToBv(ch, ctx=None):
11733 ch = _coerce_char(ch, ctx)
11734 return ch.to_bv()
11735

◆ CharToInt()

CharToInt ( ch,
ctx = None )

Definition at line 11736 of file z3py.py.

11736def CharToInt(ch, ctx=None):
11737 ch = _coerce_char(ch, ctx)
11738 return ch.to_int()
11739

◆ CharVal()

CharVal ( ch,
ctx = None )

Definition at line 11719 of file z3py.py.

11719def CharVal(ch, ctx=None):
11720 ctx = _get_ctx(ctx)
11721 if isinstance(ch, str):
11722 ch = ord(ch)
11723 if not isinstance(ch, int):
11724 raise Z3Exception("character value should be an ordinal")
11725 return _to_expr_ref(Z3_mk_char(ctx.ref(), ch), ctx)
11726
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 12195 of file z3py.py.

12195def Complement(re):
12196 """Create the complement regular expression."""
12197 return ReRef(Z3_mk_re_complement(re.ctx_ref(), re.as_ast()), re.ctx)
12198
12199
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 4259 of file z3py.py.

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

9577def Cond(p, t1, t2, ctx=None):
9578 """Return a tactic that applies tactic `t1` to a goal if probe `p` evaluates to true, and `t2` otherwise.
9579
9580 >>> t = Cond(Probe('is-qfnra'), Tactic('qfnra'), Tactic('smt'))
9581 """
9582 p = _to_probe(p, ctx)
9583 t1 = _to_tactic(t1, ctx)
9584 t2 = _to_tactic(t2, ctx)
9585 return Tactic(Z3_tactic_cond(t1.ctx.ref(), p.probe, t1.tactic, t2.tactic), t1.ctx)
9586
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 1550 of file z3py.py.

1550def Const(name, sort):
1551 """Create a constant of the given sort.
1552
1553 >>> Const('x', IntSort())
1554 x
1555 """
1556 if z3_debug():
1557 _z3_assert(isinstance(sort, SortRef), "Z3 sort expected")
1558 ctx = sort.ctx
1559 return _to_expr_ref(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), sort.ast), ctx)
1560
1561

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

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

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

11914def Contains(a, b):
11915 """Check if 'a' contains 'b'
11916 >>> s1 = Contains("abc", "ab")
11917 >>> simplify(s1)
11918 True
11919 >>> s2 = Contains("abc", "bc")
11920 >>> simplify(s2)
11921 True
11922 >>> x, y, z = Strings('x y z')
11923 >>> s3 = Contains(Concat(x,y,z), y)
11924 >>> simplify(s3)
11925 True
11926 """
11927 ctx = _get_ctx2(a, b)
11928 a = _coerce_seq(a, ctx)
11929 b = _coerce_seq(b, ctx)
11930 return BoolRef(Z3_mk_seq_contains(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
11931
11932
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 5660 of file z3py.py.

5660def CreateDatatypes(*ds):
5661 """Create mutually recursive Z3 datatypes using 1 or more Datatype helper objects.
5662
5663 In the following example we define a Tree-List using two mutually recursive datatypes.
5664
5665 >>> TreeList = Datatype('TreeList')
5666 >>> Tree = Datatype('Tree')
5667 >>> # Tree has two constructors: leaf and node
5668 >>> Tree.declare('leaf', ('val', IntSort()))
5669 >>> # a node contains a list of trees
5670 >>> Tree.declare('node', ('children', TreeList))
5671 >>> TreeList.declare('nil')
5672 >>> TreeList.declare('cons', ('car', Tree), ('cdr', TreeList))
5673 >>> Tree, TreeList = CreateDatatypes(Tree, TreeList)
5674 >>> Tree.val(Tree.leaf(10))
5675 val(leaf(10))
5676 >>> simplify(Tree.val(Tree.leaf(10)))
5677 10
5678 >>> n1 = Tree.node(TreeList.cons(Tree.leaf(10), TreeList.cons(Tree.leaf(20), TreeList.nil)))
5679 >>> n1
5680 node(cons(leaf(10), cons(leaf(20), nil)))
5681 >>> n2 = Tree.node(TreeList.cons(n1, TreeList.nil))
5682 >>> simplify(n2 == n1)
5683 False
5684 >>> simplify(TreeList.car(Tree.children(n2)) == n1)
5685 True
5686 """
5687 ds = _get_args(ds)
5688 if z3_debug():
5689 _z3_assert(len(ds) > 0, "At least one Datatype must be specified")
5690 _z3_assert(all([isinstance(d, Datatype) for d in ds]), "Arguments must be Datatypes")
5691 _z3_assert(all([d.ctx == ds[0].ctx for d in ds]), "Context mismatch")
5692 _z3_assert(all([d.constructors != [] for d in ds]), "Non-empty Datatypes expected")
5693 ctx = ds[0].ctx
5694 num = len(ds)
5695 names = (Symbol * num)()
5696 out = (Sort * num)()
5697 clists = (ConstructorList * num)()
5698 to_delete = []
5699 for i in range(num):
5700 d = ds[i]
5701 names[i] = to_symbol(d.name, ctx)
5702 num_cs = len(d.constructors)
5703 cs = (Constructor * num_cs)()
5704 for j in range(num_cs):
5705 c = d.constructors[j]
5706 cname = to_symbol(c[0], ctx)
5707 rname = to_symbol(c[1], ctx)
5708 fs = c[2]
5709 num_fs = len(fs)
5710 fnames = (Symbol * num_fs)()
5711 sorts = (Sort * num_fs)()
5712 refs = (ctypes.c_uint * num_fs)()
5713 for k in range(num_fs):
5714 fname = fs[k][0]
5715 ftype = fs[k][1]
5716 fnames[k] = to_symbol(fname, ctx)
5717 if isinstance(ftype, Datatype):
5718 if z3_debug():
5719 _z3_assert(
5720 ds.count(ftype) == 1,
5721 "One and only one occurrence of each datatype is expected",
5722 )
5723 sorts[k] = None
5724 refs[k] = ds.index(ftype)
5725 else:
5726 if z3_debug():
5727 _z3_assert(is_sort(ftype), "Z3 sort expected")
5728 sorts[k] = ftype.ast
5729 refs[k] = 0
5730 cs[j] = Z3_mk_constructor(ctx.ref(), cname, rname, num_fs, fnames, sorts, refs)
5731 to_delete.append(ScopedConstructor(cs[j], ctx))
5732 clists[i] = Z3_mk_constructor_list(ctx.ref(), num_cs, cs)
5733 to_delete.append(ScopedConstructorList(clists[i], ctx))
5734 Z3_mk_datatypes(ctx.ref(), num, names, out, clists)
5735 result = []
5736 # Create a field for every constructor, recognizer and accessor
5737 for i in range(num):
5738 dref = DatatypeSortRef(out[i], ctx)
5739 num_cs = dref.num_constructors()
5740 for j in range(num_cs):
5741 cref = dref.constructor(j)
5742 cref_name = cref.name()
5743 cref_arity = cref.arity()
5744 if cref.arity() == 0:
5745 cref = cref()
5746 setattr(dref, cref_name, cref)
5747 rref = dref.recognizer(j)
5748 setattr(dref, "is_" + cref_name, rref)
5749 for k in range(cref_arity):
5750 aref = dref.accessor(j, k)
5751 setattr(dref, aref.name(), aref)
5752 result.append(dref)
5753 return tuple(result)
5754
5755
void Z3_API Z3_mk_datatypes(Z3_context c, unsigned num_sorts, Z3_symbol const sort_names[], Z3_sort sorts[], Z3_constructor_list constructor_lists[])
Create mutually recursive datatypes.
Z3_constructor_list Z3_API Z3_mk_constructor_list(Z3_context c, unsigned num_constructors, Z3_constructor const constructors[])
Create list of constructors.
Z3_constructor Z3_API Z3_mk_constructor(Z3_context c, Z3_symbol name, Z3_symbol recognizer, unsigned num_fields, Z3_symbol const field_names[], Z3_sort const sorts[], unsigned sort_refs[])
Create a constructor.

Referenced by Datatype.create().

◆ CreatePolymorphicDatatype()

CreatePolymorphicDatatype ( d,
type_params )
Create a single polymorphic Z3 datatype with explicit type parameters.

`d` is a `Datatype` helper object whose constructors have been declared.
`type_params` is a list of type variables created with `DeclareTypeVar`.
Constructor field sorts may reference these type variables, and self-recursive
fields may reference `d` directly.

>>> A = DeclareTypeVar('A')
>>> Pair = Datatype('Pair')
>>> Pair.declare('pair', ('fst', A), ('snd', A))
>>> Pair = CreatePolymorphicDatatype(Pair, [A])

Definition at line 5756 of file z3py.py.

5756def CreatePolymorphicDatatype(d, type_params):
5757 """Create a single polymorphic Z3 datatype with explicit type parameters.
5758
5759 `d` is a `Datatype` helper object whose constructors have been declared.
5760 `type_params` is a list of type variables created with `DeclareTypeVar`.
5761 Constructor field sorts may reference these type variables, and self-recursive
5762 fields may reference `d` directly.
5763
5764 >>> A = DeclareTypeVar('A')
5765 >>> Pair = Datatype('Pair')
5766 >>> Pair.declare('pair', ('fst', A), ('snd', A))
5767 >>> Pair = CreatePolymorphicDatatype(Pair, [A])
5768 """
5769 if z3_debug():
5770 _z3_assert(isinstance(d, Datatype), "Datatype expected")
5771 _z3_assert(d.constructors != [], "Non-empty Datatype expected")
5772 ctx = d.ctx
5773 name = to_symbol(d.name, ctx)
5774 num_params = len(type_params)
5775 params_arr = (Sort * num_params)()
5776 for i, p in enumerate(type_params):
5777 if z3_debug():
5778 _z3_assert(is_sort(p), "Z3 sort expected for type parameter")
5779 params_arr[i] = p.ast
5780 num_cs = len(d.constructors)
5781 cs = (Constructor * num_cs)()
5782 to_delete = []
5783 for j in range(num_cs):
5784 c = d.constructors[j]
5785 cname = to_symbol(c[0], ctx)
5786 rname = to_symbol(c[1], ctx)
5787 fs = c[2]
5788 num_fs = len(fs)
5789 fnames = (Symbol * num_fs)()
5790 sorts = (Sort * num_fs)()
5791 refs = (ctypes.c_uint * num_fs)()
5792 for k in range(num_fs):
5793 fname = fs[k][0]
5794 ftype = fs[k][1]
5795 fnames[k] = to_symbol(fname, ctx)
5796 if isinstance(ftype, Datatype):
5797 if z3_debug():
5798 _z3_assert(ftype is d, "Only self-recursive references are supported in polymorphic datatypes. Use CreateDatatypes for mutually recursive datatypes.")
5799 sorts[k] = None
5800 refs[k] = 0
5801 else:
5802 if z3_debug():
5803 _z3_assert(is_sort(ftype), "Z3 sort expected")
5804 sorts[k] = ftype.ast
5805 refs[k] = 0
5806 cs[j] = Z3_mk_constructor(ctx.ref(), cname, rname, num_fs, fnames, sorts, refs)
5807 to_delete.append(ScopedConstructor(cs[j], ctx))
5808 out = Z3_mk_polymorphic_datatype(ctx.ref(), name, num_params, params_arr, num_cs, cs)
5809 dref = DatatypeSortRef(out, ctx)
5810 num_cs_actual = dref.num_constructors()
5811 for j in range(num_cs_actual):
5812 cref = dref.constructor(j)
5813 cref_name = cref.name()
5814 cref_arity = cref.arity()
5815 if cref_arity == 0:
5816 cref = cref()
5817 setattr(dref, cref_name, cref)
5818 rref = dref.recognizer(j)
5819 setattr(dref, "is_" + cref_name, rref)
5820 for k in range(cref_arity):
5821 aref = dref.accessor(j, k)
5822 setattr(dref, aref.name(), aref)
5823 return dref
5824
5825
Z3_sort Z3_API Z3_mk_polymorphic_datatype(Z3_context c, Z3_symbol name, unsigned num_parameters, Z3_sort parameters[], unsigned num_constructors, Z3_constructor constructors[])
Create a parametric datatype with explicit type parameters.

Referenced by Datatype.create_polymorphic().

◆ DatatypeSort()

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

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

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

Definition at line 5956 of file z3py.py.

5956def DatatypeSort(name, params=None, ctx=None):
5957 """Create a reference to a sort that was declared, or will be declared, as a recursive datatype.
5958
5959 Args:
5960 name: name of the datatype sort
5961 params: optional list/tuple of sort parameters for parametric datatypes
5962 ctx: Z3 context (optional)
5963
5964 Example:
5965 >>> # Non-parametric datatype
5966 >>> TreeRef = DatatypeSort('Tree')
5967 >>> # Parametric datatype with one parameter
5968 >>> ListIntRef = DatatypeSort('List', [IntSort()])
5969 >>> # Parametric datatype with multiple parameters
5970 >>> PairRef = DatatypeSort('Pair', [IntSort(), BoolSort()])
5971 """
5972 ctx = _get_ctx(ctx)
5973 if params is None or len(params) == 0:
5974 return DatatypeSortRef(Z3_mk_datatype_sort(ctx.ref(), to_symbol(name, ctx), 0, (Sort * 0)()), ctx)
5975 else:
5976 _params = (Sort * len(params))()
5977 for i in range(len(params)):
5978 _params[i] = params[i].ast
5979 return DatatypeSortRef(Z3_mk_datatype_sort(ctx.ref(), to_symbol(name, ctx), len(params), _params), ctx)
5980
Z3_sort Z3_API Z3_mk_datatype_sort(Z3_context c, Z3_symbol name, unsigned num_params, Z3_sort const params[])
create a forward reference to a recursive datatype being declared. The forward reference can be used ...

◆ DeclareSort()

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

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

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

Definition at line 734 of file z3py.py.

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

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

5020def Default(a):
5021 """ Return a default value for array expression.
5022 >>> b = K(IntSort(), 1)
5023 >>> prove(Default(b) == 1)
5024 proved
5025 """
5026 if z3_debug():
5027 _z3_assert(is_array_sort(a), "First argument must be a Z3 array expression")
5028 return a.default()
5029
5030

◆ describe_probes()

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

Definition at line 9498 of file z3py.py.

9498def describe_probes():
9499 """Display a (tabular) description of all available probes in Z3."""
9500 if in_html_mode():
9501 even = True
9502 print('<table border="1" cellpadding="2" cellspacing="0">')
9503 for p in probes():
9504 if even:
9505 print('<tr style="background-color:#CFCFCF">')
9506 even = False
9507 else:
9508 print("<tr>")
9509 even = True
9510 print("<td>%s</td><td>%s</td></tr>" % (p, insert_line_breaks(probe_description(p), 40)))
9511 print("</table>")
9512 else:
9513 for p in probes():
9514 print("%s : %s" % (p, probe_description(p)))
9515
9516

◆ describe_tactics()

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

Definition at line 9292 of file z3py.py.

9292def describe_tactics():
9293 """Display a (tabular) description of all available tactics in Z3."""
9294 if in_html_mode():
9295 even = True
9296 print('<table border="1" cellpadding="2" cellspacing="0">')
9297 for t in tactics():
9298 if even:
9299 print('<tr style="background-color:#CFCFCF">')
9300 even = False
9301 else:
9302 print("<tr>")
9303 even = True
9304 print("<td>%s</td><td>%s</td></tr>" % (t, insert_line_breaks(tactic_description(t), 40)))
9305 print("</table>")
9306 else:
9307 for t in tactics():
9308 print("%s : %s" % (t, tactic_description(t)))
9309
9310

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

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

◆ Diff()

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

Definition at line 12245 of file z3py.py.

12245def Diff(a, b, ctx=None):
12246 """Create the difference regular expression
12247 """
12248 if z3_debug():
12249 _z3_assert(is_expr(a), "expression expected")
12250 _z3_assert(is_expr(b), "expression expected")
12251 return ReRef(Z3_mk_re_diff(a.ctx_ref(), a.ast, b.ast), a.ctx)
12252
Z3_ast Z3_API Z3_mk_re_diff(Z3_context c, Z3_ast re1, Z3_ast re2)
Create the difference of regular expressions.

◆ disable_trace()

disable_trace ( msg)

Definition at line 87 of file z3py.py.

87def disable_trace(msg):
89
90
void Z3_API Z3_disable_trace(Z3_string tag)
Disable tracing messages tagged as tag when Z3 is compiled in debug mode. It is a NOOP otherwise.

◆ DisjointSum()

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

Definition at line 5993 of file z3py.py.

5993def DisjointSum(name, sorts, ctx=None):
5994 """Create a named tagged union sort base on a set of underlying sorts
5995 Example:
5996 >>> sum, ((inject0, extract0), (inject1, extract1)) = DisjointSum("+", [IntSort(), StringSort()])
5997 """
5998 sum = Datatype(name, ctx)
5999 for i in range(len(sorts)):
6000 sum.declare("inject%d" % i, ("project%d" % i, sorts[i]))
6001 sum = sum.create()
6002 return sum, [(sum.constructor(i), sum.accessor(i, 0)) for i in range(len(sorts))]
6003
6004

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

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

11844def Empty(s):
11845 """Create the empty sequence of the given sort
11846 >>> e = Empty(StringSort())
11847 >>> e2 = StringVal("")
11848 >>> print(e.eq(e2))
11849 True
11850 >>> e3 = Empty(SeqSort(IntSort()))
11851 >>> print(e3)
11852 Empty(Seq(Int))
11853 >>> e4 = Empty(ReSort(SeqSort(IntSort())))
11854 >>> print(e4)
11855 Empty(ReSort(Seq(Int)))
11856 """
11857 if isinstance(s, SeqSortRef):
11858 return SeqRef(Z3_mk_seq_empty(s.ctx_ref(), s.ast), s.ctx)
11859 if isinstance(s, ReSortRef):
11860 return ReRef(Z3_mk_re_empty(s.ctx_ref(), s.ast), s.ctx)
11861 raise Z3Exception("Non-sequence, non-regular expression sort passed to Empty")
11862
11863
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 5175 of file z3py.py.

5175def EmptySet(s):
5176 """Create the empty set
5177 >>> EmptySet(IntSort())
5178 K(Int, False)
5179 """
5180 ctx = s.ctx
5181 if is_finite_set_sort(s):
5182 return FiniteSetEmpty(s)
5183 return ArrayRef(Z3_mk_empty_set(ctx.ref(), s.ast), ctx)
5184
5185
Z3_ast Z3_API Z3_mk_empty_set(Z3_context c, Z3_sort domain)
Create the empty set.

◆ enable_trace()

enable_trace ( msg)

Definition at line 83 of file z3py.py.

83def enable_trace(msg):
85
86
void Z3_API Z3_enable_trace(Z3_string tag)
Enable tracing messages tagged as tag when Z3 is compiled in debug mode. It is a NOOP otherwise.

◆ ensure_prop_closures()

ensure_prop_closures ( )

Definition at line 12364 of file z3py.py.

12364def ensure_prop_closures():
12365 global _prop_closures
12366 if _prop_closures is None:
12367 _prop_closures = PropClosures()
12368
12369

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

6005def EnumSort(name, values, ctx=None):
6006 """Return a new enumeration sort named `name` containing the given values.
6007
6008 The result is a pair (sort, list of constants).
6009 Example:
6010 >>> Color, (red, green, blue) = EnumSort('Color', ['red', 'green', 'blue'])
6011 """
6012 if z3_debug():
6013 _z3_assert(isinstance(name, str), "Name must be a string")
6014 _z3_assert(all([isinstance(v, str) for v in values]), "Enumeration sort values must be strings")
6015 _z3_assert(len(values) > 0, "At least one value expected")
6016 ctx = _get_ctx(ctx)
6017 num = len(values)
6018 _val_names = (Symbol * num)()
6019 for i in range(num):
6020 _val_names[i] = to_symbol(values[i], ctx)
6021 _values = (FuncDecl * num)()
6022 _testers = (FuncDecl * num)()
6023 name = to_symbol(name, ctx)
6024 S = DatatypeSortRef(Z3_mk_enumeration_sort(ctx.ref(), name, num, _val_names, _values, _testers), ctx)
6025 V = []
6026 for i in range(num):
6027 V.append(FuncDeclRef(_values[i], ctx))
6028 V = [a() for a in V]
6029 return S, V
6030
Z3_sort Z3_API Z3_mk_enumeration_sort(Z3_context c, Z3_symbol name, unsigned n, Z3_symbol const enum_names[], Z3_func_decl enum_consts[], Z3_func_decl enum_testers[])
Create a enumeration sort.

◆ eq()

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

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

Definition at line 503 of file z3py.py.

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

◆ Exists()

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

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


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

Definition at line 2393 of file z3py.py.

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

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

5109def Ext(a, b):
5110 """Return extensionality index for one-dimensional arrays.
5111 >> a, b = Consts('a b', SetSort(IntSort()))
5112 >> Ext(a, b)
5113 Ext(a, b)
5114 """
5115 ctx = a.ctx
5116 if z3_debug():
5117 _z3_assert(is_array_sort(a) and (is_array(b) or b.is_lambda()), "arguments must be arrays")
5118 return _to_expr_ref(Z3_mk_array_ext(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
5119
5120
Z3_ast Z3_API Z3_mk_array_ext(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create array extensionality index given two arrays with the same sort. The meaning is given by the ax...

◆ Extract()

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

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

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

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

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

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

Definition at line 4305 of file z3py.py.

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

9535def FailIf(p, ctx=None):
9536 """Return a tactic that fails if the probe `p` evaluates to true.
9537 Otherwise, it returns the input goal unmodified.
9538
9539 In the following example, the tactic applies 'simplify' if and only if there are
9540 more than 2 constraints in the goal.
9541
9542 >>> t = OrElse(FailIf(Probe('size') > 2), Tactic('simplify'))
9543 >>> x, y = Ints('x y')
9544 >>> g = Goal()
9545 >>> g.add(x > 0)
9546 >>> g.add(y > 0)
9547 >>> t(g)
9548 [[x > 0, y > 0]]
9549 >>> g.add(x == y + 1)
9550 >>> t(g)
9551 [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
9552 """
9553 p = _to_probe(p, ctx)
9554 return Tactic(Z3_tactic_fail_if(p.ctx.ref(), p.probe), p.ctx)
9555
9556
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 8433 of file z3py.py.

8433def FiniteDomainSort(name, sz, ctx=None):
8434 """Create a named finite domain sort of a given size sz"""
8435 if not isinstance(name, Symbol):
8436 name = to_symbol(name)
8437 ctx = _get_ctx(ctx)
8438 return FiniteDomainSortRef(Z3_mk_finite_domain_sort(ctx.ref(), name, sz), ctx)
8439
8440
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 8503 of file z3py.py.

8503def FiniteDomainVal(val, sort, ctx=None):
8504 """Return a Z3 finite-domain value. If `ctx=None`, then the global context is used.
8505
8506 >>> s = FiniteDomainSort('S', 256)
8507 >>> FiniteDomainVal(255, s)
8508 255
8509 >>> FiniteDomainVal('100', s)
8510 100
8511 """
8512 if z3_debug():
8513 _z3_assert(is_finite_domain_sort(sort), "Expected finite-domain sort")
8514 ctx = sort.ctx
8515 return FiniteDomainNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), sort.ast), ctx)
8516
8517

◆ FiniteFieldBitsum()

FiniteFieldBitsum ( * args)

Definition at line 12729 of file z3py.py.

12729def FiniteFieldBitsum(*args):
12730 args = _get_args(args)
12731 if len(args) < 2 or not isinstance(args[0], FiniteFieldRef):
12732 raise Z3Exception("bitsum needs at least two field arguments")
12733 field = args[0].sort()
12734 values = [field.cast(a) for a in args]
12735 raw = (Ast * len(values))(*[a.as_ast() for a in values])
12736 return FiniteFieldRef(Z3_mk_ff_bitsum(field.ctx_ref(), len(values), raw), field.ctx)
Z3_ast Z3_API Z3_mk_ff_bitsum(Z3_context c, unsigned n, Z3_ast const args[])
Weighted sum a0 + 2*a1 + 4*a2 + ... (does not constrain arguments to bits).

◆ FiniteFieldElem()

FiniteFieldElem ( name,
field,
ctx = None )

Definition at line 12717 of file z3py.py.

12717def FiniteFieldElem(name, field, ctx=None):
12718 if not isinstance(field, FiniteFieldSortRef):
12719 field = FiniteFieldSort(field, ctx)
12720 return Const(name, field)
12721
12722

◆ FiniteFieldElems()

FiniteFieldElems ( names,
field,
ctx = None )

Definition at line 12723 of file z3py.py.

12723def FiniteFieldElems(names, field, ctx=None):
12724 if not isinstance(field, FiniteFieldSortRef):
12725 field = FiniteFieldSort(field, ctx)
12726 return [Const(name, field) for name in (names.split() if isinstance(names, str) else names)]
12727
12728

◆ FiniteFieldSort()

FiniteFieldSort ( prime,
ctx = None )

Definition at line 12704 of file z3py.py.

12704def FiniteFieldSort(prime, ctx=None):
12705 ctx = _get_ctx(ctx)
12706 return FiniteFieldSortRef(Z3_mk_finite_field_sort(ctx.ref(), str(prime)), ctx)
12707
12708
Z3_sort Z3_API Z3_mk_finite_field_sort(Z3_context c, Z3_string prime)
Create a prime-field sort. Large moduli undergo probable-prime screening.

◆ FiniteFieldVal()

FiniteFieldVal ( value,
field,
ctx = None )

Definition at line 12709 of file z3py.py.

12709def FiniteFieldVal(value, field, ctx=None):
12710 if not isinstance(field, FiniteFieldSortRef):
12711 field = FiniteFieldSort(field, ctx)
12712 if not isinstance(value, (int, str)):
12713 raise Z3Exception("finite-field value must be an integer")
12714 return FiniteFieldRef(Z3_mk_numeral(field.ctx_ref(), str(value), field.ast), field.ctx)
12715
12716

◆ FiniteSetDifference()

FiniteSetDifference ( s1,
s2 )
Create the set difference of two finite sets.
>>> a = Const('a', FiniteSetSort(IntSort()))
>>> b = Const('b', FiniteSetSort(IntSort()))
>>> FiniteSetDifference(a, b)
set.difference(a, b)

Definition at line 5440 of file z3py.py.

5440def FiniteSetDifference(s1, s2):
5441 """Create the set difference of two finite sets.
5442 >>> a = Const('a', FiniteSetSort(IntSort()))
5443 >>> b = Const('b', FiniteSetSort(IntSort()))
5444 >>> FiniteSetDifference(a, b)
5445 set.difference(a, b)
5446 """
5447 ctx = _ctx_from_ast_arg_list([s1, s2])
5448 return FiniteSetRef(Z3_mk_finite_set_difference(ctx.ref(), s1.as_ast(), s2.as_ast()), ctx)
5449
5450
Z3_ast Z3_API Z3_mk_finite_set_difference(Z3_context c, Z3_ast s1, Z3_ast s2)
Create the set difference of two finite sets.

Referenced by FiniteSetRef.__sub__(), and SetDifference().

◆ FiniteSetEmpty()

FiniteSetEmpty ( set_sort)
Create an empty finite set of the given sort.
>>> s = FiniteSetSort(IntSort())
>>> FiniteSetEmpty(s)
set.empty

Definition at line 5399 of file z3py.py.

5399def FiniteSetEmpty(set_sort):
5400 """Create an empty finite set of the given sort.
5401 >>> s = FiniteSetSort(IntSort())
5402 >>> FiniteSetEmpty(s)
5403 set.empty
5404 """
5405 ctx = set_sort.ctx
5406 return FiniteSetRef(Z3_mk_finite_set_empty(ctx.ref(), set_sort.ast), ctx)
5407
5408
Z3_ast Z3_API Z3_mk_finite_set_empty(Z3_context c, Z3_sort set_sort)
Create an empty finite set of the given sort.

Referenced by FiniteSetSortRef.cast(), and EmptySet().

◆ FiniteSetFilter()

FiniteSetFilter ( f,
set )
Filter a finite set using predicate f.
>>> f = Array('f', IntSort(), BoolSort())
>>> a = Const('a', FiniteSetSort(IntSort()))
>>> FiniteSetFilter(f, a)
set.filter(f, a)

Definition at line 5497 of file z3py.py.

5497def FiniteSetFilter(f, set):
5498 """Filter a finite set using predicate f.
5499 >>> f = Array('f', IntSort(), BoolSort())
5500 >>> a = Const('a', FiniteSetSort(IntSort()))
5501 >>> FiniteSetFilter(f, a)
5502 set.filter(f, a)
5503 """
5504 if isinstance(f, FuncDeclRef):
5505 f = AsArray(f)
5506 ctx = _ctx_from_ast_arg_list([f, set])
5507 return FiniteSetRef(Z3_mk_finite_set_filter(ctx.ref(), f.as_ast(), set.as_ast()), ctx)
5508
5509
Z3_ast Z3_API Z3_mk_finite_set_filter(Z3_context c, Z3_ast f, Z3_ast set)
Filter a finite set using a predicate.

◆ FiniteSetIntersect()

FiniteSetIntersect ( s1,
s2 )
Create the intersection of two finite sets.
>>> a = Const('a', FiniteSetSort(IntSort()))
>>> b = Const('b', FiniteSetSort(IntSort()))
>>> FiniteSetIntersect(a, b)
set.intersect(a, b)

Definition at line 5429 of file z3py.py.

5429def FiniteSetIntersect(s1, s2):
5430 """Create the intersection of two finite sets.
5431 >>> a = Const('a', FiniteSetSort(IntSort()))
5432 >>> b = Const('b', FiniteSetSort(IntSort()))
5433 >>> FiniteSetIntersect(a, b)
5434 set.intersect(a, b)
5435 """
5436 ctx = _ctx_from_ast_arg_list([s1, s2])
5437 return FiniteSetRef(Z3_mk_finite_set_intersect(ctx.ref(), s1.as_ast(), s2.as_ast()), ctx)
5438
5439
Z3_ast Z3_API Z3_mk_finite_set_intersect(Z3_context c, Z3_ast s1, Z3_ast s2)
Create the intersection of two finite sets.

Referenced by FiniteSetRef.__and__().

◆ FiniteSetMap()

FiniteSetMap ( f,
set )
Apply function f to all elements of the finite set.
>>> f = Array('f', IntSort(), IntSort())
>>> a = Const('a', FiniteSetSort(IntSort()))
>>> FiniteSetMap(f, a)
set.map(f, a)

Definition at line 5484 of file z3py.py.

5484def FiniteSetMap(f, set):
5485 """Apply function f to all elements of the finite set.
5486 >>> f = Array('f', IntSort(), IntSort())
5487 >>> a = Const('a', FiniteSetSort(IntSort()))
5488 >>> FiniteSetMap(f, a)
5489 set.map(f, a)
5490 """
5491 if isinstance(f, FuncDeclRef):
5492 f = AsArray(f)
5493 ctx = _ctx_from_ast_arg_list([f, set])
5494 return FiniteSetRef(Z3_mk_finite_set_map(ctx.ref(), f.as_ast(), set.as_ast()), ctx)
5495
5496
Z3_ast Z3_API Z3_mk_finite_set_map(Z3_context c, Z3_ast f, Z3_ast set)
Apply a function to all elements of a finite set.

◆ FiniteSetMember()

FiniteSetMember ( elem,
set )
Check if elem is a member of the finite set.
>>> a = Const('a', FiniteSetSort(IntSort()))
>>> FiniteSetMember(IntVal(1), a)
set.in(1, a)

Definition at line 5451 of file z3py.py.

5451def FiniteSetMember(elem, set):
5452 """Check if elem is a member of the finite set.
5453 >>> a = Const('a', FiniteSetSort(IntSort()))
5454 >>> FiniteSetMember(IntVal(1), a)
5455 set.in(1, a)
5456 """
5457 ctx = _ctx_from_ast_arg_list([elem, set])
5458 return BoolRef(Z3_mk_finite_set_member(ctx.ref(), elem.as_ast(), set.as_ast()), ctx)
5459
Z3_ast Z3_API Z3_mk_finite_set_member(Z3_context c, Z3_ast elem, Z3_ast set)
Check if an element is a member of a finite set.

Referenced by In().

◆ FiniteSetRange()

FiniteSetRange ( low,
high )
Create a finite set of integers in the range [low, high).
>>> FiniteSetRange(IntVal(0), IntVal(5))
set.range(0, 5)

Definition at line 5510 of file z3py.py.

5510def FiniteSetRange(low, high):
5511 """Create a finite set of integers in the range [low, high).
5512 >>> FiniteSetRange(IntVal(0), IntVal(5))
5513 set.range(0, 5)
5514 """
5515 ctx = _ctx_from_ast_arg_list([low, high])
5516 return FiniteSetRef(Z3_mk_finite_set_range(ctx.ref(), low.as_ast(), high.as_ast()), ctx)
5517
5518
Z3_ast Z3_API Z3_mk_finite_set_range(Z3_context c, Z3_ast low, Z3_ast high)
Create a finite set of integers in the range [low, high].

◆ FiniteSetSize()

FiniteSetSize ( set)
Get the size (cardinality) of a finite set.
>>> a = Const('a', FiniteSetSort(IntSort()))
>>> FiniteSetSize(a)
set.size(a)

Definition at line 5463 of file z3py.py.

5463def FiniteSetSize(set):
5464 """Get the size (cardinality) of a finite set.
5465 >>> a = Const('a', FiniteSetSort(IntSort()))
5466 >>> FiniteSetSize(a)
5467 set.size(a)
5468 """
5469 ctx = set.ctx
5470 return ArithRef(Z3_mk_finite_set_size(ctx.ref(), set.as_ast()), ctx)
5471
5472
Z3_ast Z3_API Z3_mk_finite_set_size(Z3_context c, Z3_ast set)
Get the size (cardinality) of a finite set.

◆ FiniteSetSort()

FiniteSetSort ( elem_sort)
Create a finite set sort over element sort elem_sort.
>>> s = FiniteSetSort(IntSort())
>>> s
FiniteSet(Int)

Definition at line 5390 of file z3py.py.

5390def FiniteSetSort(elem_sort):
5391 """Create a finite set sort over element sort elem_sort.
5392 >>> s = FiniteSetSort(IntSort())
5393 >>> s
5394 FiniteSet(Int)
5395 """
5396 return FiniteSetSortRef(Z3_mk_finite_set_sort(elem_sort.ctx_ref(), elem_sort.ast), elem_sort.ctx)
5397
5398
Z3_sort Z3_API Z3_mk_finite_set_sort(Z3_context c, Z3_sort elem_sort)
Create a finite set sort.

◆ FiniteSetSubset()

FiniteSetSubset ( s1,
s2 )
Check if s1 is a subset of s2.
>>> a = Const('a', FiniteSetSort(IntSort()))
>>> b = Const('b', FiniteSetSort(IntSort()))
>>> FiniteSetSubset(a, b)
set.subset(a, b)

Definition at line 5473 of file z3py.py.

5473def FiniteSetSubset(s1, s2):
5474 """Check if s1 is a subset of s2.
5475 >>> a = Const('a', FiniteSetSort(IntSort()))
5476 >>> b = Const('b', FiniteSetSort(IntSort()))
5477 >>> FiniteSetSubset(a, b)
5478 set.subset(a, b)
5479 """
5480 ctx = _ctx_from_ast_arg_list([s1, s2])
5481 return BoolRef(Z3_mk_finite_set_subset(ctx.ref(), s1.as_ast(), s2.as_ast()), ctx)
5482
5483
Z3_ast Z3_API Z3_mk_finite_set_subset(Z3_context c, Z3_ast s1, Z3_ast s2)
Check if one finite set is a subset of another.

◆ FiniteSetUnion()

FiniteSetUnion ( s1,
s2 )
Create the union of two finite sets.
>>> a = Const('a', FiniteSetSort(IntSort()))
>>> b = Const('b', FiniteSetSort(IntSort()))
>>> FiniteSetUnion(a, b)
set.union(a, b)

Definition at line 5418 of file z3py.py.

5418def FiniteSetUnion(s1, s2):
5419 """Create the union of two finite sets.
5420 >>> a = Const('a', FiniteSetSort(IntSort()))
5421 >>> b = Const('b', FiniteSetSort(IntSort()))
5422 >>> FiniteSetUnion(a, b)
5423 set.union(a, b)
5424 """
5425 ctx = _ctx_from_ast_arg_list([s1, s2])
5426 return FiniteSetRef(Z3_mk_finite_set_union(ctx.ref(), s1.as_ast(), s2.as_ast()), ctx)
5427
5428
Z3_ast Z3_API Z3_mk_finite_set_union(Z3_context c, Z3_ast s1, Z3_ast s2)
Create the union of two finite sets.

Referenced by FiniteSetRef.__or__(), and FiniteSetSortRef.cast().

◆ Float128()

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

Definition at line 10263 of file z3py.py.

10263def Float128(ctx=None):
10264 """Floating-point 128-bit (quadruple) sort."""
10265 ctx = _get_ctx(ctx)
10266 return FPSortRef(Z3_mk_fpa_sort_128(ctx.ref()), ctx)
10267
10268
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 10227 of file z3py.py.

10227def Float16(ctx=None):
10228 """Floating-point 16-bit (half) sort."""
10229 ctx = _get_ctx(ctx)
10230 return FPSortRef(Z3_mk_fpa_sort_16(ctx.ref()), ctx)
10231
10232
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 10239 of file z3py.py.

10239def Float32(ctx=None):
10240 """Floating-point 32-bit (single) sort."""
10241 ctx = _get_ctx(ctx)
10242 return FPSortRef(Z3_mk_fpa_sort_32(ctx.ref()), ctx)
10243
10244
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 10251 of file z3py.py.

10251def Float64(ctx=None):
10252 """Floating-point 64-bit (double) sort."""
10253 ctx = _get_ctx(ctx)
10254 return FPSortRef(Z3_mk_fpa_sort_64(ctx.ref()), ctx)
10255
10256
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 10257 of file z3py.py.

10257def FloatDouble(ctx=None):
10258 """Floating-point 64-bit (double) sort."""
10259 ctx = _get_ctx(ctx)
10260 return FPSortRef(Z3_mk_fpa_sort_double(ctx.ref()), ctx)
10261
10262
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 10233 of file z3py.py.

10233def FloatHalf(ctx=None):
10234 """Floating-point 16-bit (half) sort."""
10235 ctx = _get_ctx(ctx)
10236 return FPSortRef(Z3_mk_fpa_sort_half(ctx.ref()), ctx)
10237
10238
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 10269 of file z3py.py.

10269def FloatQuadruple(ctx=None):
10270 """Floating-point 128-bit (quadruple) sort."""
10271 ctx = _get_ctx(ctx)
10272 return FPSortRef(Z3_mk_fpa_sort_quadruple(ctx.ref()), ctx)
10273
10274
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 10245 of file z3py.py.

10245def FloatSingle(ctx=None):
10246 """Floating-point 32-bit (single) sort."""
10247 ctx = _get_ctx(ctx)
10248 return FPSortRef(Z3_mk_fpa_sort_single(ctx.ref()), ctx)
10249
10250
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 2375 of file z3py.py.

2375def ForAll(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2376 """Create a Z3 forall formula.
2377
2378 The parameters `weight`, `qid`, `skid`, `patterns` and `no_patterns` are optional annotations.
2379
2380 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2381 >>> x = Int('x')
2382 >>> y = Int('y')
2383 >>> ForAll([x, y], f(x, y) >= x)
2384 ForAll([x, y], f(x, y) >= x)
2385 >>> ForAll([x, y], f(x, y) >= x, patterns=[ f(x, y) ])
2386 ForAll([x, y], f(x, y) >= x)
2387 >>> ForAll([x, y], f(x, y) >= x, weight=10)
2388 ForAll([x, y], f(x, y) >= x)
2389 """
2390 return _mk_quantifier(True, vs, body, weight, qid, skid, patterns, no_patterns)
2391
2392

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

10937def FP(name, fpsort, ctx=None):
10938 """Return a floating-point constant named `name`.
10939 `fpsort` is the floating-point sort.
10940 If `ctx=None`, then the global context is used.
10941
10942 >>> x = FP('x', FPSort(8, 24))
10943 >>> is_fp(x)
10944 True
10945 >>> x.ebits()
10946 8
10947 >>> x.sort()
10948 FPSort(8, 24)
10949 >>> word = FPSort(8, 24)
10950 >>> x2 = FP('x', word)
10951 >>> eq(x, x2)
10952 True
10953 """
10954 if isinstance(fpsort, FPSortRef) and ctx is None:
10955 ctx = fpsort.ctx
10956 else:
10957 ctx = _get_ctx(ctx)
10958 return FPRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), fpsort.ast), ctx)
10959
10960

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

10980def fpAbs(a, ctx=None):
10981 """Create a Z3 floating-point absolute value expression.
10982
10983 >>> s = FPSort(8, 24)
10984 >>> rm = RNE()
10985 >>> x = FPVal(1.0, s)
10986 >>> fpAbs(x)
10987 fpAbs(1)
10988 >>> y = FPVal(-20.0, s)
10989 >>> y
10990 -1.25*(2**4)
10991 >>> fpAbs(y)
10992 fpAbs(-1.25*(2**4))
10993 >>> fpAbs(-1.25*(2**4))
10994 fpAbs(-1.25*(2**4))
10995 >>> fpAbs(x).sort()
10996 FPSort(8, 24)
10997 """
10998 ctx = _get_ctx(ctx)
10999 [a] = _coerce_fp_expr_list([a], ctx)
11000 return FPRef(Z3_mk_fpa_abs(ctx.ref(), a.as_ast()), ctx)
11001
11002
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 11071 of file z3py.py.

11071def fpAdd(rm, a, b, ctx=None):
11072 """Create a Z3 floating-point addition expression.
11073
11074 >>> s = FPSort(8, 24)
11075 >>> rm = RNE()
11076 >>> x = FP('x', s)
11077 >>> y = FP('y', s)
11078 >>> fpAdd(rm, x, y)
11079 x + y
11080 >>> fpAdd(RTZ(), x, y) # default rounding mode is RTZ
11081 fpAdd(RTZ(), x, y)
11082 >>> fpAdd(rm, x, y).sort()
11083 FPSort(8, 24)
11084 """
11085 return _mk_fp_bin(Z3_mk_fpa_add, rm, a, b, ctx)
11086
11087

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

11393def fpBVToFP(v, sort, ctx=None):
11394 """Create a Z3 floating-point conversion expression that represents the
11395 conversion from a bit-vector term to a floating-point term.
11396
11397 >>> x_bv = BitVecVal(0x3F800000, 32)
11398 >>> x_fp = fpBVToFP(x_bv, Float32())
11399 >>> x_fp
11400 fpToFP(1065353216)
11401 >>> simplify(x_fp)
11402 1
11403 """
11404 _z3_assert(is_bv(v), "First argument must be a Z3 bit-vector expression")
11405 _z3_assert(is_fp_sort(sort), "Second argument must be a Z3 floating-point sort.")
11406 ctx = _get_ctx(ctx)
11407 return FPRef(Z3_mk_fpa_to_fp_bv(ctx.ref(), v.ast, sort.ast), ctx)
11408
11409
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 11118 of file z3py.py.

11118def fpDiv(rm, a, b, ctx=None):
11119 """Create a Z3 floating-point division expression.
11120
11121 >>> s = FPSort(8, 24)
11122 >>> rm = RNE()
11123 >>> x = FP('x', s)
11124 >>> y = FP('y', s)
11125 >>> fpDiv(rm, x, y)
11126 x / y
11127 >>> fpDiv(rm, x, y).sort()
11128 FPSort(8, 24)
11129 """
11130 return _mk_fp_bin(Z3_mk_fpa_div, rm, a, b, ctx)
11131
11132

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

11301def fpEQ(a, b, ctx=None):
11302 """Create the Z3 floating-point expression `fpEQ(other, self)`.
11303
11304 >>> x, y = FPs('x y', FPSort(8, 24))
11305 >>> fpEQ(x, y)
11306 fpEQ(x, y)
11307 >>> fpEQ(x, y).sexpr()
11308 '(fp.eq x y)'
11309 """
11310 return _mk_fp_bin_pred(Z3_mk_fpa_eq, a, b, ctx)
11311
11312

◆ fpFMA()

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

Definition at line 11177 of file z3py.py.

11177def fpFMA(rm, a, b, c, ctx=None):
11178 """Create a Z3 floating-point fused multiply-add expression.
11179 """
11180 return _mk_fp_tern(Z3_mk_fpa_fma, rm, a, b, c, ctx)
11181
11182

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

11325def fpFP(sgn, exp, sig, ctx=None):
11326 """Create the Z3 floating-point value `fpFP(sgn, sig, exp)` from the three bit-vectors sgn, sig, and exp.
11327
11328 >>> s = FPSort(8, 24)
11329 >>> x = fpFP(BitVecVal(1, 1), BitVecVal(2**7-1, 8), BitVecVal(2**22, 23))
11330 >>> print(x)
11331 fpFP(1, 127, 4194304)
11332 >>> xv = FPVal(-1.5, s)
11333 >>> print(xv)
11334 -1.5
11335 >>> slvr = Solver()
11336 >>> slvr.add(fpEQ(x, xv))
11337 >>> slvr.check()
11338 sat
11339 >>> xv = FPVal(+1.5, s)
11340 >>> print(xv)
11341 1.5
11342 >>> slvr = Solver()
11343 >>> slvr.add(fpEQ(x, xv))
11344 >>> slvr.check()
11345 unsat
11346 """
11347 _z3_assert(is_bv(sgn) and is_bv(exp) and is_bv(sig), "sort mismatch")
11348 _z3_assert(sgn.sort().size() == 1, "sort mismatch")
11349 ctx = _get_ctx(ctx)
11350 _z3_assert(ctx == sgn.ctx == exp.ctx == sig.ctx, "context mismatch")
11351 return FPRef(Z3_mk_fpa_fp(ctx.ref(), sgn.ast, exp.ast, sig.ast), ctx)
11352
11353

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

11410def fpFPToFP(rm, v, sort, ctx=None):
11411 """Create a Z3 floating-point conversion expression that represents the
11412 conversion from a floating-point term to a floating-point term of different precision.
11413
11414 >>> x_sgl = FPVal(1.0, Float32())
11415 >>> x_dbl = fpFPToFP(RNE(), x_sgl, Float64())
11416 >>> x_dbl
11417 fpToFP(RNE(), 1)
11418 >>> simplify(x_dbl)
11419 1
11420 >>> x_dbl.sort()
11421 FPSort(11, 53)
11422 """
11423 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
11424 _z3_assert(is_fp(v), "Second argument must be a Z3 floating-point expression.")
11425 _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
11426 ctx = _get_ctx(ctx)
11427 return FPRef(Z3_mk_fpa_to_fp_float(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
11428
11429
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 11289 of file z3py.py.

11289def fpGEQ(a, b, ctx=None):
11290 """Create the Z3 floating-point expression `other >= self`.
11291
11292 >>> x, y = FPs('x y', FPSort(8, 24))
11293 >>> fpGEQ(x, y)
11294 x >= y
11295 >>> (x >= y).sexpr()
11296 '(fp.geq x y)'
11297 """
11298 return _mk_fp_bin_pred(Z3_mk_fpa_geq, a, b, ctx)
11299
11300

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

11277def fpGT(a, b, ctx=None):
11278 """Create the Z3 floating-point expression `other > self`.
11279
11280 >>> x, y = FPs('x y', FPSort(8, 24))
11281 >>> fpGT(x, y)
11282 x > y
11283 >>> (x > y).sexpr()
11284 '(fp.gt x y)'
11285 """
11286 return _mk_fp_bin_pred(Z3_mk_fpa_gt, a, b, ctx)
11287
11288

◆ fpInfinity()

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

Definition at line 10838 of file z3py.py.

10838def fpInfinity(s, negative):
10839 """Create a Z3 floating-point +oo or -oo term."""
10840 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10841 _z3_assert(isinstance(negative, bool), "expected Boolean flag")
10842 return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, negative), s.ctx)
10843
10844
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 11207 of file z3py.py.

11207def fpIsInf(a, ctx=None):
11208 """Create a Z3 floating-point isInfinite expression.
11209
11210 >>> s = FPSort(8, 24)
11211 >>> x = FP('x', s)
11212 >>> fpIsInf(x)
11213 fpIsInf(x)
11214 """
11215 return _mk_fp_unary_pred(Z3_mk_fpa_is_infinite, a, ctx)
11216
11217

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

11195def fpIsNaN(a, ctx=None):
11196 """Create a Z3 floating-point isNaN expression.
11197
11198 >>> s = FPSort(8, 24)
11199 >>> x = FP('x', s)
11200 >>> y = FP('y', s)
11201 >>> fpIsNaN(x)
11202 fpIsNaN(x)
11203 """
11204 return _mk_fp_unary_pred(Z3_mk_fpa_is_nan, a, ctx)
11205
11206

◆ fpIsNegative()

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

Definition at line 11236 of file z3py.py.

11236def fpIsNegative(a, ctx=None):
11237 """Create a Z3 floating-point isNegative expression.
11238 """
11239 return _mk_fp_unary_pred(Z3_mk_fpa_is_negative, a, ctx)
11240
11241

◆ fpIsNormal()

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

Definition at line 11224 of file z3py.py.

11224def fpIsNormal(a, ctx=None):
11225 """Create a Z3 floating-point isNormal expression.
11226 """
11227 return _mk_fp_unary_pred(Z3_mk_fpa_is_normal, a, ctx)
11228
11229

◆ fpIsPositive()

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

Definition at line 11242 of file z3py.py.

11242def fpIsPositive(a, ctx=None):
11243 """Create a Z3 floating-point isPositive expression.
11244 """
11245 return _mk_fp_unary_pred(Z3_mk_fpa_is_positive, a, ctx)
11246
11247

◆ fpIsSubnormal()

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

Definition at line 11230 of file z3py.py.

11230def fpIsSubnormal(a, ctx=None):
11231 """Create a Z3 floating-point isSubnormal expression.
11232 """
11233 return _mk_fp_unary_pred(Z3_mk_fpa_is_subnormal, a, ctx)
11234
11235

◆ fpIsZero()

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

Definition at line 11218 of file z3py.py.

11218def fpIsZero(a, ctx=None):
11219 """Create a Z3 floating-point isZero expression.
11220 """
11221 return _mk_fp_unary_pred(Z3_mk_fpa_is_zero, a, ctx)
11222
11223

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

11265def fpLEQ(a, b, ctx=None):
11266 """Create the Z3 floating-point expression `other <= self`.
11267
11268 >>> x, y = FPs('x y', FPSort(8, 24))
11269 >>> fpLEQ(x, y)
11270 x <= y
11271 >>> (x <= y).sexpr()
11272 '(fp.leq x y)'
11273 """
11274 return _mk_fp_bin_pred(Z3_mk_fpa_leq, a, b, ctx)
11275
11276

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

11253def fpLT(a, b, ctx=None):
11254 """Create the Z3 floating-point expression `other < self`.
11255
11256 >>> x, y = FPs('x y', FPSort(8, 24))
11257 >>> fpLT(x, y)
11258 x < y
11259 >>> (x < y).sexpr()
11260 '(fp.lt x y)'
11261 """
11262 return _mk_fp_bin_pred(Z3_mk_fpa_lt, a, b, ctx)
11263
11264

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

11162def fpMax(a, b, ctx=None):
11163 """Create a Z3 floating-point maximum expression.
11164
11165 >>> s = FPSort(8, 24)
11166 >>> rm = RNE()
11167 >>> x = FP('x', s)
11168 >>> y = FP('y', s)
11169 >>> fpMax(x, y)
11170 fpMax(x, y)
11171 >>> fpMax(x, y).sort()
11172 FPSort(8, 24)
11173 """
11174 return _mk_fp_bin_norm(Z3_mk_fpa_max, a, b, ctx)
11175
11176

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

11147def fpMin(a, b, ctx=None):
11148 """Create a Z3 floating-point minimum expression.
11149
11150 >>> s = FPSort(8, 24)
11151 >>> rm = RNE()
11152 >>> x = FP('x', s)
11153 >>> y = FP('y', s)
11154 >>> fpMin(x, y)
11155 fpMin(x, y)
11156 >>> fpMin(x, y).sort()
11157 FPSort(8, 24)
11158 """
11159 return _mk_fp_bin_norm(Z3_mk_fpa_min, a, b, ctx)
11160
11161

◆ fpMinusInfinity()

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

Definition at line 10832 of file z3py.py.

10832def fpMinusInfinity(s):
10833 """Create a Z3 floating-point -oo term."""
10834 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10835 return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, True), s.ctx)
10836
10837

◆ fpMinusZero()

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

Definition at line 10851 of file z3py.py.

10851def fpMinusZero(s):
10852 """Create a Z3 floating-point -0.0 term."""
10853 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10854 return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, True), s.ctx)
10855
10856
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 11103 of file z3py.py.

11103def fpMul(rm, a, b, ctx=None):
11104 """Create a Z3 floating-point multiplication expression.
11105
11106 >>> s = FPSort(8, 24)
11107 >>> rm = RNE()
11108 >>> x = FP('x', s)
11109 >>> y = FP('y', s)
11110 >>> fpMul(rm, x, y)
11111 x * y
11112 >>> fpMul(rm, x, y).sort()
11113 FPSort(8, 24)
11114 """
11115 return _mk_fp_bin(Z3_mk_fpa_mul, rm, a, b, ctx)
11116
11117

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

10798def fpNaN(s):
10799 """Create a Z3 floating-point NaN term.
10800
10801 >>> s = FPSort(8, 24)
10802 >>> set_fpa_pretty(True)
10803 >>> fpNaN(s)
10804 NaN
10805 >>> pb = get_fpa_pretty()
10806 >>> set_fpa_pretty(False)
10807 >>> fpNaN(s)
10808 fpNaN(FPSort(8, 24))
10809 >>> set_fpa_pretty(pb)
10810 """
10811 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10812 return FPNumRef(Z3_mk_fpa_nan(s.ctx_ref(), s.ast), s.ctx)
10813
10814
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 11003 of file z3py.py.

11003def fpNeg(a, ctx=None):
11004 """Create a Z3 floating-point addition expression.
11005
11006 >>> s = FPSort(8, 24)
11007 >>> rm = RNE()
11008 >>> x = FP('x', s)
11009 >>> fpNeg(x)
11010 -x
11011 >>> fpNeg(x).sort()
11012 FPSort(8, 24)
11013 """
11014 ctx = _get_ctx(ctx)
11015 [a] = _coerce_fp_expr_list([a], ctx)
11016 return FPRef(Z3_mk_fpa_neg(ctx.ref(), a.as_ast()), ctx)
11017
11018
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 11313 of file z3py.py.

11313def fpNEQ(a, b, ctx=None):
11314 """Create the Z3 floating-point expression `Not(fpEQ(other, self))`.
11315
11316 >>> x, y = FPs('x y', FPSort(8, 24))
11317 >>> fpNEQ(x, y)
11318 Not(fpEQ(x, y))
11319 >>> (x != y).sexpr()
11320 '(distinct x y)'
11321 """
11322 return Not(fpEQ(a, b, ctx))
11323
11324

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

10815def fpPlusInfinity(s):
10816 """Create a Z3 floating-point +oo term.
10817
10818 >>> s = FPSort(8, 24)
10819 >>> pb = get_fpa_pretty()
10820 >>> set_fpa_pretty(True)
10821 >>> fpPlusInfinity(s)
10822 +oo
10823 >>> set_fpa_pretty(False)
10824 >>> fpPlusInfinity(s)
10825 fpPlusInfinity(FPSort(8, 24))
10826 >>> set_fpa_pretty(pb)
10827 """
10828 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10829 return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, False), s.ctx)
10830
10831

◆ fpPlusZero()

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

Definition at line 10845 of file z3py.py.

10845def fpPlusZero(s):
10846 """Create a Z3 floating-point +0.0 term."""
10847 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10848 return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, False), s.ctx)
10849
10850

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

11430def fpRealToFP(rm, v, sort, ctx=None):
11431 """Create a Z3 floating-point conversion expression that represents the
11432 conversion from a real term to a floating-point term.
11433
11434 >>> x_r = RealVal(1.5)
11435 >>> x_fp = fpRealToFP(RNE(), x_r, Float32())
11436 >>> x_fp
11437 fpToFP(RNE(), 3/2)
11438 >>> simplify(x_fp)
11439 1.5
11440 """
11441 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
11442 _z3_assert(is_real(v), "Second argument must be a Z3 expression or real sort.")
11443 _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
11444 ctx = _get_ctx(ctx)
11445 return FPRef(Z3_mk_fpa_to_fp_real(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
11446
11447
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 11133 of file z3py.py.

11133def fpRem(a, b, ctx=None):
11134 """Create a Z3 floating-point remainder expression.
11135
11136 >>> s = FPSort(8, 24)
11137 >>> x = FP('x', s)
11138 >>> y = FP('y', s)
11139 >>> fpRem(x, y)
11140 fpRem(x, y)
11141 >>> fpRem(x, y).sort()
11142 FPSort(8, 24)
11143 """
11144 return _mk_fp_bin_norm(Z3_mk_fpa_rem, a, b, ctx)
11145
11146

◆ fpRoundToIntegral()

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

Definition at line 11189 of file z3py.py.

11189def fpRoundToIntegral(rm, a, ctx=None):
11190 """Create a Z3 floating-point roundToIntegral expression.
11191 """
11192 return _mk_fp_unary(Z3_mk_fpa_round_to_integral, rm, a, ctx)
11193
11194

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

10961def FPs(names, fpsort, ctx=None):
10962 """Return an array of floating-point constants.
10963
10964 >>> x, y, z = FPs('x y z', FPSort(8, 24))
10965 >>> x.sort()
10966 FPSort(8, 24)
10967 >>> x.sbits()
10968 24
10969 >>> x.ebits()
10970 8
10971 >>> fpMul(RNE(), fpAdd(RNE(), x, y), z)
10972 (x + y) * z
10973 """
10974 ctx = _get_ctx(ctx)
10975 if isinstance(names, str):
10976 names = names.split(" ")
10977 return [FP(name, fpsort, ctx) for name in names]
10978
10979

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

11448def fpSignedToFP(rm, v, sort, ctx=None):
11449 """Create a Z3 floating-point conversion expression that represents the
11450 conversion from a signed bit-vector term (encoding an integer) to a floating-point term.
11451
11452 >>> x_signed = BitVecVal(-5, BitVecSort(32))
11453 >>> x_fp = fpSignedToFP(RNE(), x_signed, Float32())
11454 >>> x_fp
11455 fpToFP(RNE(), 4294967291)
11456 >>> simplify(x_fp)
11457 -1.25*(2**2)
11458 """
11459 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
11460 _z3_assert(is_bv(v), "Second argument must be a Z3 bit-vector expression")
11461 _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
11462 ctx = _get_ctx(ctx)
11463 return FPRef(Z3_mk_fpa_to_fp_signed(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
11464
11465
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 10734 of file z3py.py.

10734def FPSort(ebits, sbits, ctx=None):
10735 """Return a Z3 floating-point sort of the given sizes. If `ctx=None`, then the global context is used.
10736
10737 >>> Single = FPSort(8, 24)
10738 >>> Double = FPSort(11, 53)
10739 >>> Single
10740 FPSort(8, 24)
10741 >>> x = Const('x', Single)
10742 >>> eq(x, FP('x', FPSort(8, 24)))
10743 True
10744 """
10745 ctx = _get_ctx(ctx)
10746 return FPSortRef(Z3_mk_fpa_sort(ctx.ref(), ebits, sbits), ctx)
10747
10748
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 11183 of file z3py.py.

11183def fpSqrt(rm, a, ctx=None):
11184 """Create a Z3 floating-point square root expression.
11185 """
11186 return _mk_fp_unary(Z3_mk_fpa_sqrt, rm, a, ctx)
11187
11188

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

11088def fpSub(rm, a, b, ctx=None):
11089 """Create a Z3 floating-point subtraction expression.
11090
11091 >>> s = FPSort(8, 24)
11092 >>> rm = RNE()
11093 >>> x = FP('x', s)
11094 >>> y = FP('y', s)
11095 >>> fpSub(rm, x, y)
11096 x - y
11097 >>> fpSub(rm, x, y).sort()
11098 FPSort(8, 24)
11099 """
11100 return _mk_fp_bin(Z3_mk_fpa_sub, rm, a, b, ctx)
11101
11102

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

11354def fpToFP(a1, a2=None, a3=None, ctx=None):
11355 """Create a Z3 floating-point conversion expression from other term sorts
11356 to floating-point.
11357
11358 From a bit-vector term in IEEE 754-2008 format:
11359 >>> x = FPVal(1.0, Float32())
11360 >>> x_bv = fpToIEEEBV(x)
11361 >>> simplify(fpToFP(x_bv, Float32()))
11362 1
11363
11364 From a floating-point term with different precision:
11365 >>> x = FPVal(1.0, Float32())
11366 >>> x_db = fpToFP(RNE(), x, Float64())
11367 >>> x_db.sort()
11368 FPSort(11, 53)
11369
11370 From a real term:
11371 >>> x_r = RealVal(1.5)
11372 >>> simplify(fpToFP(RNE(), x_r, Float32()))
11373 1.5
11374
11375 From a signed bit-vector term:
11376 >>> x_signed = BitVecVal(-5, BitVecSort(32))
11377 >>> simplify(fpToFP(RNE(), x_signed, Float32()))
11378 -1.25*(2**2)
11379 """
11380 ctx = _get_ctx(ctx)
11381 if is_bv(a1) and is_fp_sort(a2):
11382 return FPRef(Z3_mk_fpa_to_fp_bv(ctx.ref(), a1.ast, a2.ast), ctx)
11383 elif is_fprm(a1) and is_fp(a2) and is_fp_sort(a3):
11384 return FPRef(Z3_mk_fpa_to_fp_float(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
11385 elif is_fprm(a1) and is_real(a2) and is_fp_sort(a3):
11386 return FPRef(Z3_mk_fpa_to_fp_real(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
11387 elif is_fprm(a1) and is_bv(a2) and is_fp_sort(a3):
11388 return FPRef(Z3_mk_fpa_to_fp_signed(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
11389 else:
11390 raise Z3Exception("Unsupported combination of arguments for conversion to floating-point term.")
11391
11392

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

11484def fpToFPUnsigned(rm, x, s, ctx=None):
11485 """Create a Z3 floating-point conversion expression, from unsigned bit-vector to floating-point expression."""
11486 if z3_debug():
11487 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
11488 _z3_assert(is_bv(x), "Second argument must be a Z3 bit-vector expression")
11489 _z3_assert(is_fp_sort(s), "Third argument must be Z3 floating-point sort")
11490 ctx = _get_ctx(ctx)
11491 return FPRef(Z3_mk_fpa_to_fp_unsigned(ctx.ref(), rm.ast, x.ast, s.ast), ctx)
11492
11493
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 11558 of file z3py.py.

11558def fpToIEEEBV(x, ctx=None):
11559 """\brief Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.
11560
11561 The size of the resulting bit-vector is automatically determined.
11562
11563 Note that IEEE 754-2008 allows multiple different representations of NaN. This conversion
11564 knows only one NaN and it will always produce the same bit-vector representation of
11565 that NaN.
11566
11567 >>> x = FP('x', FPSort(8, 24))
11568 >>> y = fpToIEEEBV(x)
11569 >>> print(is_fp(x))
11570 True
11571 >>> print(is_bv(y))
11572 True
11573 >>> print(is_fp(y))
11574 False
11575 >>> print(is_bv(x))
11576 False
11577 """
11578 if z3_debug():
11579 _z3_assert(is_fp(x), "First argument must be a Z3 floating-point expression")
11580 ctx = _get_ctx(ctx)
11581 return BitVecRef(Z3_mk_fpa_to_ieee_bv(ctx.ref(), x.ast), ctx)
11582
11583
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 11538 of file z3py.py.

11538def fpToReal(x, ctx=None):
11539 """Create a Z3 floating-point conversion expression, from floating-point expression to real.
11540
11541 >>> x = FP('x', FPSort(8, 24))
11542 >>> y = fpToReal(x)
11543 >>> print(is_fp(x))
11544 True
11545 >>> print(is_real(y))
11546 True
11547 >>> print(is_fp(y))
11548 False
11549 >>> print(is_real(x))
11550 False
11551 """
11552 if z3_debug():
11553 _z3_assert(is_fp(x), "First argument must be a Z3 floating-point expression")
11554 ctx = _get_ctx(ctx)
11555 return ArithRef(Z3_mk_fpa_to_real(ctx.ref(), x.ast), ctx)
11556
11557
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 11494 of file z3py.py.

11494def fpToSBV(rm, x, s, ctx=None):
11495 """Create a Z3 floating-point conversion expression, from floating-point expression to signed bit-vector.
11496
11497 >>> x = FP('x', FPSort(8, 24))
11498 >>> y = fpToSBV(RTZ(), x, BitVecSort(32))
11499 >>> print(is_fp(x))
11500 True
11501 >>> print(is_bv(y))
11502 True
11503 >>> print(is_fp(y))
11504 False
11505 >>> print(is_bv(x))
11506 False
11507 """
11508 if z3_debug():
11509 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
11510 _z3_assert(is_fp(x), "Second argument must be a Z3 floating-point expression")
11511 _z3_assert(is_bv_sort(s), "Third argument must be Z3 bit-vector sort")
11512 ctx = _get_ctx(ctx)
11513 return BitVecRef(Z3_mk_fpa_to_sbv(ctx.ref(), rm.ast, x.ast, s.size()), ctx)
11514
11515
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 11516 of file z3py.py.

11516def fpToUBV(rm, x, s, ctx=None):
11517 """Create a Z3 floating-point conversion expression, from floating-point expression to unsigned bit-vector.
11518
11519 >>> x = FP('x', FPSort(8, 24))
11520 >>> y = fpToUBV(RTZ(), x, BitVecSort(32))
11521 >>> print(is_fp(x))
11522 True
11523 >>> print(is_bv(y))
11524 True
11525 >>> print(is_fp(y))
11526 False
11527 >>> print(is_bv(x))
11528 False
11529 """
11530 if z3_debug():
11531 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
11532 _z3_assert(is_fp(x), "Second argument must be a Z3 floating-point expression")
11533 _z3_assert(is_bv_sort(s), "Third argument must be Z3 bit-vector sort")
11534 ctx = _get_ctx(ctx)
11535 return BitVecRef(Z3_mk_fpa_to_ubv(ctx.ref(), rm.ast, x.ast, s.size()), ctx)
11536
11537
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 11466 of file z3py.py.

11466def fpUnsignedToFP(rm, v, sort, ctx=None):
11467 """Create a Z3 floating-point conversion expression that represents the
11468 conversion from an unsigned bit-vector term (encoding an integer) to a floating-point term.
11469
11470 >>> x_signed = BitVecVal(-5, BitVecSort(32))
11471 >>> x_fp = fpUnsignedToFP(RNE(), x_signed, Float32())
11472 >>> x_fp
11473 fpToFPUnsigned(RNE(), 4294967291)
11474 >>> simplify(x_fp)
11475 1*(2**32)
11476 """
11477 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
11478 _z3_assert(is_bv(v), "Second argument must be a Z3 bit-vector expression")
11479 _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
11480 ctx = _get_ctx(ctx)
11481 return FPRef(Z3_mk_fpa_to_fp_unsigned(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
11482
11483

◆ FPVal()

FPVal ( sig,
exp = None,
fps = None,
ctx = None )
Return a floating-point value of value `sig * 2**exp` and sort `fps`.
If `exp=None`, then the exponent is zero.
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
>>> FPVal(1.0, 3, Float32())
1*(2**3)
>>> FPVal(1, 3, Float32())
1*(2**3)
>>> FPVal("1.5", -2, Float32())
1.5*(2**-2)
>>> FPVal("1.25*(2**4)", 1, Float32())
1.25*(2**5)
>>> FPVal("1.25*(2**4)", -4, Float32())
1.25
>>> FPVal("1p2", 3, Float32())
1*(2**5)
>>> FPVal("1P2", 3, Float32())
1*(2**5)
>>> FPVal("1.5p-2", 2, Float32())
1.5
>>> FPVal(1.5, 0, Float32())
1.5
>>> FPVal(1.5, fps=Float32())
1.5
>>> [FPVal(v, 3, Float32()) for v in
...  [float("nan"), float("inf"), float("-inf"), 0.0, -0.0]]
[NaN, +oo, -oo, +0.0, -0.0]
>>> [FPVal(v, -2, Float32()) for v in
...  ["NaN", "+oo", "-oo", "+0.0", "-0.0"]]
[NaN, +oo, -oo, +0.0, -0.0]

Definition at line 10864 of file z3py.py.

10864def FPVal(sig, exp=None, fps=None, ctx=None):
10865 """Return a floating-point value of value `sig * 2**exp` and sort `fps`.
10866 If `exp=None`, then the exponent is zero.
10867 If `ctx=None`, then the global context is used.
10868
10869 >>> v = FPVal(20.0, FPSort(8, 24))
10870 >>> v
10871 1.25*(2**4)
10872 >>> print("0x%.8x" % v.exponent_as_long(False))
10873 0x00000004
10874 >>> v = FPVal(2.25, FPSort(8, 24))
10875 >>> v
10876 1.125*(2**1)
10877 >>> v = FPVal(-2.25, FPSort(8, 24))
10878 >>> v
10879 -1.125*(2**1)
10880 >>> FPVal(-0.0, FPSort(8, 24))
10881 -0.0
10882 >>> FPVal(0.0, FPSort(8, 24))
10883 +0.0
10884 >>> FPVal(+0.0, FPSort(8, 24))
10885 +0.0
10886 >>> FPVal(1.0, 3, Float32())
10887 1*(2**3)
10888 >>> FPVal(1, 3, Float32())
10889 1*(2**3)
10890 >>> FPVal("1.5", -2, Float32())
10891 1.5*(2**-2)
10892 >>> FPVal("1.25*(2**4)", 1, Float32())
10893 1.25*(2**5)
10894 >>> FPVal("1.25*(2**4)", -4, Float32())
10895 1.25
10896 >>> FPVal("1p2", 3, Float32())
10897 1*(2**5)
10898 >>> FPVal("1P2", 3, Float32())
10899 1*(2**5)
10900 >>> FPVal("1.5p-2", 2, Float32())
10901 1.5
10902 >>> FPVal(1.5, 0, Float32())
10903 1.5
10904 >>> FPVal(1.5, fps=Float32())
10905 1.5
10906 >>> [FPVal(v, 3, Float32()) for v in
10907 ... [float("nan"), float("inf"), float("-inf"), 0.0, -0.0]]
10908 [NaN, +oo, -oo, +0.0, -0.0]
10909 >>> [FPVal(v, -2, Float32()) for v in
10910 ... ["NaN", "+oo", "-oo", "+0.0", "-0.0"]]
10911 [NaN, +oo, -oo, +0.0, -0.0]
10912 """
10913 ctx = _get_ctx(ctx)
10914 if is_fp_sort(exp):
10915 fps = exp
10916 exp = None
10917 elif fps is None:
10918 fps = _dflt_fps(ctx)
10919 _z3_assert(is_fp_sort(fps), "sort mismatch")
10920 if exp is None:
10921 exp = 0
10922 val = _to_float_str(sig)
10923 if val == "NaN" or val == "nan":
10924 return fpNaN(fps)
10925 elif val == "-0.0":
10926 return fpMinusZero(fps)
10927 elif val == "0.0" or val == "+0.0":
10928 return fpPlusZero(fps)
10929 elif val == "+oo" or val == "+inf" or val == "+Inf":
10930 return fpPlusInfinity(fps)
10931 elif val == "-oo" or val == "-inf" or val == "-Inf":
10932 return fpMinusInfinity(fps)
10933 else:
10934 return FPNumRef(Z3_mk_numeral(ctx.ref(), _to_float_str(sig, exp), fps.ast), ctx)
10935
10936

◆ fpZero()

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

Definition at line 10857 of file z3py.py.

10857def fpZero(s, negative):
10858 """Create a Z3 floating-point +0.0 or -0.0 term."""
10859 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10860 _z3_assert(isinstance(negative, bool), "expected Boolean flag")
10861 return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, negative), s.ctx)
10862
10863

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

1914def FreshBool(prefix="b", ctx=None):
1915 """Return a fresh Boolean constant in the given context using the given prefix.
1916
1917 If `ctx=None`, then the global context is used.
1918
1919 >>> b1 = FreshBool()
1920 >>> b2 = FreshBool()
1921 >>> eq(b1, b2)
1922 False
1923 """
1924 ctx = _get_ctx(ctx)
1925 return BoolRef(Z3_mk_fresh_const(ctx.ref(), prefix, BoolSort(ctx).ast), ctx)
1926
1927
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 1577 of file z3py.py.

1577def FreshConst(sort, prefix="c"):
1578 """Create a fresh constant of a specified sort"""
1579 if z3_debug():
1580 _z3_assert(is_sort(sort), f"Z3 sort expected, got {type(sort)}")
1581 ctx = _get_ctx(sort.ctx)
1582 return _to_expr_ref(Z3_mk_fresh_const(ctx.ref(), prefix, sort.ast), ctx)
1583
1584

◆ FreshFunction()

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

Definition at line 947 of file z3py.py.

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

3457def FreshInt(prefix="x", ctx=None):
3458 """Return a fresh integer constant in the given context using the given prefix.
3459
3460 >>> x = FreshInt()
3461 >>> y = FreshInt()
3462 >>> eq(x, y)
3463 False
3464 >>> x.sort()
3465 Int
3466 """
3467 ctx = _get_ctx(ctx)
3468 return ArithRef(Z3_mk_fresh_const(ctx.ref(), prefix, IntSort(ctx).ast), ctx)
3469
3470

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

3514def FreshReal(prefix="b", ctx=None):
3515 """Return a fresh real constant in the given context using the given prefix.
3516
3517 >>> x = FreshReal()
3518 >>> y = FreshReal()
3519 >>> eq(x, y)
3520 False
3521 >>> x.sort()
3522 Real
3523 """
3524 ctx = _get_ctx(ctx)
3525 return ArithRef(Z3_mk_fresh_const(ctx.ref(), prefix, RealSort(ctx).ast), ctx)
3526
3527

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

11864def Full(s):
11865 """Create the regular expression that accepts the universal language
11866 >>> e = Full(ReSort(SeqSort(IntSort())))
11867 >>> print(e)
11868 Full(ReSort(Seq(Int)))
11869 >>> e1 = Full(ReSort(StringSort()))
11870 >>> print(e1)
11871 Full(ReSort(String))
11872 """
11873 if isinstance(s, ReSortRef):
11874 return ReRef(Z3_mk_re_full(s.ctx_ref(), s.ast), s.ctx)
11875 raise Z3Exception("Non-sequence, non-regular expression sort passed to Full")
11876
11877
11878
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 5186 of file z3py.py.

5186def FullSet(s):
5187 """Create the full set
5188 >>> FullSet(IntSort())
5189 K(Int, True)
5190 """
5191 ctx = s.ctx
5192 return ArrayRef(Z3_mk_full_set(ctx.ref(), s.ast), ctx)
5193
5194
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 924 of file z3py.py.

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

7350def get_as_array_func(n):
7351 """Return the function declaration f associated with a Z3 expression of the form (_ as-array f)."""
7352 if z3_debug():
7353 _z3_assert(is_as_array(n), "as-array Z3 expression expected.")
7354 return FuncDeclRef(Z3_get_as_array_func_decl(n.ctx.ref(), n.as_ast()), n.ctx)
7355
Z3_func_decl Z3_API Z3_get_as_array_func_decl(Z3_context c, Z3_ast a)
Return the function declaration f associated with a (_ as_array f) node.

Referenced by ModelRef.get_interp().

◆ get_ctx()

Context get_ctx ( ctx)

Definition at line 294 of file z3py.py.

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

◆ get_default_fp_sort()

get_default_fp_sort ( ctx = None)

Definition at line 10146 of file z3py.py.

10146def get_default_fp_sort(ctx=None):
10147 return FPSort(_dflt_fpsort_ebits, _dflt_fpsort_sbits, ctx)
10148
10149

◆ get_default_rounding_mode()

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

Definition at line 10113 of file z3py.py.

10113def get_default_rounding_mode(ctx=None):
10114 """Retrieves the global default rounding mode."""
10115 global _dflt_rounding_mode
10116 if _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO:
10117 return RTZ(ctx)
10118 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE:
10119 return RTN(ctx)
10120 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE:
10121 return RTP(ctx)
10122 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN:
10123 return RNE(ctx)
10124 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY:
10125 return RNA(ctx)
10126
10127

◆ get_full_version()

get_full_version ( )

Definition at line 109 of file z3py.py.

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

◆ get_map_func()

get_map_func ( a)
Return the function declaration associated with a Z3 map array expression.

>>> f = Function('f', IntSort(), IntSort())
>>> b = Array('b', IntSort(), IntSort())
>>> a  = Map(f, b)
>>> eq(f, get_map_func(a))
True
>>> get_map_func(a)
f
>>> get_map_func(a)(0)
f(0)

Definition at line 4915 of file z3py.py.

4915def get_map_func(a):
4916 """Return the function declaration associated with a Z3 map array expression.
4917
4918 >>> f = Function('f', IntSort(), IntSort())
4919 >>> b = Array('b', IntSort(), IntSort())
4920 >>> a = Map(f, b)
4921 >>> eq(f, get_map_func(a))
4922 True
4923 >>> get_map_func(a)
4924 f
4925 >>> get_map_func(a)(0)
4926 f(0)
4927 """
4928 if z3_debug():
4929 _z3_assert(is_map(a), "Z3 array map expression expected.")
4930 return FuncDeclRef(
4932 a.ctx_ref(),
4933 Z3_get_decl_ast_parameter(a.ctx_ref(), a.decl().ast, 0),
4934 ),
4935 ctx=a.ctx,
4936 )
4937
4938
Z3_func_decl Z3_API Z3_to_func_decl(Z3_context c, Z3_ast a)
Convert an AST into a FUNC_DECL_AST. This is just type casting.
Z3_ast Z3_API Z3_get_decl_ast_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the expression value associated with an expression parameter.

◆ get_param()

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

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

Definition at line 334 of file z3py.py.

334def get_param(name):
335 """Return the value of a Z3 global (or module) parameter
336
337 >>> get_param('nlsat.reorder')
338 'true'
339 """
340 ptr = (ctypes.c_char_p * 1)()
341 if Z3_global_param_get(str(name), ptr):
342 r = z3core._to_pystr(ptr[0])
343 return r
344 raise Z3Exception("failed to retrieve value for '%s'" % name)
345
bool Z3_API Z3_global_param_get(Z3_string param_id, Z3_string_ptr param_value)
Get a global (or module) parameter.

◆ get_var_index()

get_var_index ( a)
Return the de-Bruijn index of the Z3 bounded variable `a`.

>>> x = Int('x')
>>> y = Int('y')
>>> is_var(x)
False
>>> is_const(x)
True
>>> f = Function('f', IntSort(), IntSort(), IntSort())
>>> # Z3 replaces x and y with bound variables when ForAll is executed.
>>> q = ForAll([x, y], f(x, y) == x + y)
>>> q.body()
f(Var(1), Var(0)) == Var(1) + Var(0)
>>> b = q.body()
>>> b.arg(0)
f(Var(1), Var(0))
>>> v1 = b.arg(0).arg(0)
>>> v2 = b.arg(0).arg(1)
>>> v1
Var(1)
>>> v2
Var(0)
>>> get_var_index(v1)
1
>>> get_var_index(v2)
0

Definition at line 1448 of file z3py.py.

1448def get_var_index(a):
1449 """Return the de-Bruijn index of the Z3 bounded variable `a`.
1450
1451 >>> x = Int('x')
1452 >>> y = Int('y')
1453 >>> is_var(x)
1454 False
1455 >>> is_const(x)
1456 True
1457 >>> f = Function('f', IntSort(), IntSort(), IntSort())
1458 >>> # Z3 replaces x and y with bound variables when ForAll is executed.
1459 >>> q = ForAll([x, y], f(x, y) == x + y)
1460 >>> q.body()
1461 f(Var(1), Var(0)) == Var(1) + Var(0)
1462 >>> b = q.body()
1463 >>> b.arg(0)
1464 f(Var(1), Var(0))
1465 >>> v1 = b.arg(0).arg(0)
1466 >>> v2 = b.arg(0).arg(1)
1467 >>> v1
1468 Var(1)
1469 >>> v2
1470 Var(0)
1471 >>> get_var_index(v1)
1472 1
1473 >>> get_var_index(v2)
1474 0
1475 """
1476 if z3_debug():
1477 _z3_assert(is_var(a), "Z3 bound variable expected")
1478 return int(Z3_get_index_value(a.ctx.ref(), a.as_ast()))
1479
1480
unsigned Z3_API Z3_get_index_value(Z3_context c, Z3_ast a)
Return index of de-Bruijn bound variable.

◆ get_version()

get_version ( )

Definition at line 100 of file z3py.py.

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

◆ get_version_string()

get_version_string ( )

Definition at line 91 of file z3py.py.

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

◆ help_simplify()

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

Definition at line 9619 of file z3py.py.

9619def help_simplify():
9620 """Return a string describing all options available for Z3 `simplify` procedure."""
9621 print(Z3_simplify_get_help(main_ctx().ref()))
9622
9623
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 1494 of file z3py.py.

1494def If(a, b, c, ctx=None):
1495 """Create a Z3 if-then-else expression.
1496
1497 >>> x = Int('x')
1498 >>> y = Int('y')
1499 >>> max = If(x > y, x, y)
1500 >>> max
1501 If(x > y, x, y)
1502 >>> simplify(max)
1503 If(x <= y, y, x)
1504 """
1505 if isinstance(a, Probe) or isinstance(b, Tactic) or isinstance(c, Tactic):
1506 return Cond(a, b, c, ctx)
1507 else:
1508 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b, c], ctx))
1509 s = BoolSort(ctx)
1510 a = s.cast(a)
1511 b, c = _coerce_exprs(b, c, ctx)
1512 if z3_debug():
1513 _z3_assert(a.ctx == b.ctx, "Context mismatch")
1514 return _to_expr_ref(Z3_mk_ite(ctx.ref(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
1515
1516
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__(), BoolRef.__mul__(), and ToReal().

◆ Implies()

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

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

Definition at line 1928 of file z3py.py.

1928def Implies(a, b, ctx=None):
1929 """Create a Z3 implies expression.
1930
1931 >>> p, q = Bools('p q')
1932 >>> Implies(p, q)
1933 Implies(p, q)
1934 """
1935 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1936 s = BoolSort(ctx)
1937 a = s.cast(a)
1938 b = s.cast(b)
1939 return BoolRef(Z3_mk_implies(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
1940
1941
Z3_ast Z3_API Z3_mk_implies(Z3_context c, Z3_ast t1, Z3_ast t2)
Create an AST node representing t1 implies t2.

◆ In()

In ( elem,
set )

Definition at line 5460 of file z3py.py.

5460def In(elem, set):
5461 return FiniteSetMember(elem, set)
5462

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

11948def IndexOf(s, substr, offset=None):
11949 """Retrieve the index of substring within a string starting at a specified offset.
11950 >>> simplify(IndexOf("abcabc", "bc", 0))
11951 1
11952 >>> simplify(IndexOf("abcabc", "bc", 2))
11953 4
11954 """
11955 if offset is None:
11956 offset = IntVal(0)
11957 ctx = None
11958 if is_expr(offset):
11959 ctx = offset.ctx
11960 ctx = _get_ctx2(s, substr, ctx)
11961 s = _coerce_seq(s, ctx)
11962 substr = _coerce_seq(substr, ctx)
11963 if _is_int(offset):
11964 offset = IntVal(offset, ctx)
11965 return ArithRef(Z3_mk_seq_index(s.ctx_ref(), s.as_ast(), substr.as_ast(), offset.as_ast()), s.ctx)
11966
11967
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 12097 of file z3py.py.

12097def InRe(s, re):
12098 """Create regular expression membership test
12099 >>> re = Union(Re("a"),Re("b"))
12100 >>> print (simplify(InRe("a", re)))
12101 True
12102 >>> print (simplify(InRe("b", re)))
12103 True
12104 >>> print (simplify(InRe("c", re)))
12105 False
12106 """
12107 s = _coerce_seq(s, re.ctx)
12108 return BoolRef(Z3_mk_seq_in_re(s.ctx_ref(), s.as_ast(), re.as_ast()), s.ctx)
12109
12110
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 3418 of file z3py.py.

3418def Int(name, ctx=None):
3419 """Return an integer constant named `name`. If `ctx=None`, then the global context is used.
3420
3421 >>> x = Int('x')
3422 >>> is_int(x)
3423 True
3424 >>> is_int(x + 1)
3425 True
3426 """
3427 ctx = _get_ctx(ctx)
3428 return ArithRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), IntSort(ctx).ast), ctx)
3429
3430

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

4173def Int2BV(a, num_bits):
4174 """Return the z3 expression Int2BV(a, num_bits).
4175 It is a bit-vector of width num_bits and represents the
4176 modulo of a by 2^num_bits
4177 """
4178 ctx = a.ctx
4179 return BitVecRef(Z3_mk_int2bv(ctx.ref(), num_bits, a.as_ast()), ctx)
4180
4181
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 12139 of file z3py.py.

12139def Intersect(*args):
12140 """Create intersection of regular expressions.
12141 >>> re = Intersect(Re("a"), Re("b"), Re("c"))
12142 """
12143 args = _get_args(args)
12144 sz = len(args)
12145 if z3_debug():
12146 _z3_assert(sz > 0, "At least one argument expected.")
12147 arg0 = args[0]
12148 if is_finite_set(arg0):
12149 for a in args[1:]:
12150 if not is_finite_set(a):
12151 raise Z3Exception("All arguments must be regular expressions or finite sets.")
12152 arg0 = arg0 & a
12153 return arg0
12154 if z3_debug():
12155 _z3_assert(all([is_re(a) for a in args]), "All arguments must be regular expressions.")
12156 if sz == 1:
12157 return args[0]
12158 ctx = args[0].ctx
12159 v = (Ast * sz)()
12160 for i in range(sz):
12161 v[i] = args[i].as_ast()
12162 return ReRef(Z3_mk_re_intersect(ctx.ref(), sz, v), ctx)
12163
12164
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 3431 of file z3py.py.

3431def Ints(names, ctx=None):
3432 """Return a tuple of Integer constants.
3433
3434 >>> x, y, z = Ints('x y z')
3435 >>> Sum(x, y, z)
3436 x + y + z
3437 """
3438 ctx = _get_ctx(ctx)
3439 if isinstance(names, str):
3440 names = names.split(" ")
3441 return [Int(name, ctx) for name in names]
3442
3443

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

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

12039def IntToStr(s):
12040 """Convert integer expression to string"""
12041 if not is_expr(s):
12042 s = _py2expr(s)
12043 return SeqRef(Z3_mk_int_to_str(s.ctx_ref(), s.as_ast()), s.ctx)
12044
12045
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 3354 of file z3py.py.

3354def IntVal(val, ctx=None):
3355 """Return a Z3 integer value. If `ctx=None`, then the global context is used.
3356
3357 >>> IntVal(1)
3358 1
3359 >>> IntVal("100")
3360 100
3361 """
3362 ctx = _get_ctx(ctx)
3363 return IntNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), IntSort(ctx).ast), ctx)
3364
3365

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

3444def IntVector(prefix, sz, ctx=None):
3445 """Return a list of integer constants of size `sz`.
3446
3447 >>> X = IntVector('x', 3)
3448 >>> X
3449 [x__0, x__1, x__2]
3450 >>> Sum(X)
3451 x__0 + x__1 + x__2
3452 """
3453 ctx = _get_ctx(ctx)
3454 return [Int("%s__%s" % (prefix, i), ctx) for i in range(sz)]
3455
3456

◆ is_add()

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

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

Definition at line 2956 of file z3py.py.

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

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

2942def is_algebraic_value(a):
2943 """Return `True` if `a` is an algebraic value of sort Real.
2944
2945 >>> is_algebraic_value(RealVal("3/5"))
2946 False
2947 >>> n = simplify(Sqrt(2))
2948 >>> n
2949 1.4142135623?
2950 >>> is_algebraic_value(n)
2951 True
2952 """
2953 return is_arith(a) and a.is_real() and _is_algebraic(a.ctx, a.as_ast())
2954
2955

◆ is_and()

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

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

Definition at line 1764 of file z3py.py.

1764def is_and(a : Any) -> bool:
1765 """Return `True` if `a` is a Z3 and expression.
1766
1767 >>> p, q = Bools('p q')
1768 >>> is_and(And(p, q))
1769 True
1770 >>> is_and(Or(p, q))
1771 False
1772 """
1773 return is_app_of(a, Z3_OP_AND)
1774
1775

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

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

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

◆ is_app_of()

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

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

Definition at line 1481 of file z3py.py.

1481def is_app_of(a, k):
1482 """Return `True` if `a` is an application of the given kind `k`.
1483
1484 >>> x = Int('x')
1485 >>> n = x + 1
1486 >>> is_app_of(n, Z3_OP_ADD)
1487 True
1488 >>> is_app_of(n, Z3_OP_MUL)
1489 False
1490 """
1491 return is_app(a) and a.kind() == k
1492
1493

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

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

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

◆ is_arith_sort()

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

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

Definition at line 2517 of file z3py.py.

2517def is_arith_sort(s : Any) -> bool:
2518 """Return `True` if s is an arithmetical sort (type).
2519
2520 >>> is_arith_sort(IntSort())
2521 True
2522 >>> is_arith_sort(RealSort())
2523 True
2524 >>> is_arith_sort(BoolSort())
2525 False
2526 >>> n = Int('x') + 1
2527 >>> is_arith_sort(n.sort())
2528 True
2529 """
2530 return isinstance(s, ArithSortRef)
2531
2532

Referenced by ArithSortRef.subsort().

◆ is_array()

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

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

Definition at line 4850 of file z3py.py.

4850def is_array(a : Any) -> bool:
4851 """Return `True` if `a` is a Z3 array expression.
4852
4853 >>> a = Array('a', IntSort(), IntSort())
4854 >>> is_array(a)
4855 True
4856 >>> is_array(Store(a, 0, 1))
4857 True
4858 >>> is_array(a[0])
4859 False
4860 """
4861 return isinstance(a, ArrayRef)
4862
4863

Referenced by Ext(), and Map().

◆ is_array_sort()

is_array_sort ( a)

Definition at line 4846 of file z3py.py.

4846def is_array_sort(a):
4847 return Z3_get_sort_kind(a.ctx.ref(), Z3_get_sort(a.ctx.ref(), a.ast)) == Z3_ARRAY_SORT
4848
4849

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

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

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

◆ is_ast()

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

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

Definition at line 482 of file z3py.py.

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

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

◆ is_bool()

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

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

Definition at line 1714 of file z3py.py.

1714def is_bool(a : Any) -> bool:
1715 """Return `True` if `a` is a Z3 Boolean expression.
1716
1717 >>> p = Bool('p')
1718 >>> is_bool(p)
1719 True
1720 >>> q = Bool('q')
1721 >>> is_bool(And(p, q))
1722 True
1723 >>> x = Real('x')
1724 >>> is_bool(x)
1725 False
1726 >>> is_bool(x == 0)
1727 True
1728 """
1729 return isinstance(a, BoolRef)
1730
1731

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

4121def is_bv(a):
4122 """Return `True` if `a` is a Z3 bit-vector expression.
4123
4124 >>> b = BitVec('b', 32)
4125 >>> is_bv(b)
4126 True
4127 >>> is_bv(b + 10)
4128 True
4129 >>> is_bv(Int('x'))
4130 False
4131 """
4132 return isinstance(a, BitVecRef)
4133
4134

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

3648def is_bv_sort(s):
3649 """Return True if `s` is a Z3 bit-vector sort.
3650
3651 >>> is_bv_sort(BitVecSort(32))
3652 True
3653 >>> is_bv_sort(IntSort())
3654 False
3655 """
3656 return isinstance(s, BitVecSortRef)
3657
3658

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

4135def is_bv_value(a):
4136 """Return `True` if `a` is a Z3 bit-vector numeral value.
4137
4138 >>> b = BitVec('b', 32)
4139 >>> is_bv_value(b)
4140 False
4141 >>> b = BitVecVal(10, 32)
4142 >>> b
4143 10
4144 >>> is_bv_value(b)
4145 True
4146 """
4147 return is_bv(a) and _is_numeral(a.ctx, a.as_ast())
4148
4149

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

1404def is_const(a):
1405 """Return `True` if `a` is Z3 constant/variable expression.
1406
1407 >>> a = Int('a')
1408 >>> is_const(a)
1409 True
1410 >>> is_const(a + 1)
1411 False
1412 >>> is_const(1)
1413 False
1414 >>> is_const(IntVal(1))
1415 True
1416 >>> x = Int('x')
1417 >>> is_const(ForAll(x, x >= 0))
1418 False
1419 """
1420 return is_app(a) and a.num_args() == 0
1421
1422

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

4864def is_const_array(a):
4865 """Return `True` if `a` is a Z3 constant array.
4866
4867 >>> a = K(IntSort(), 10)
4868 >>> is_const_array(a)
4869 True
4870 >>> a = Array('a', IntSort(), IntSort())
4871 >>> is_const_array(a)
4872 False
4873 """
4874 return is_app_of(a, Z3_OP_CONST_ARRAY)
4875
4876

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

4906def is_default(a):
4907 """Return `True` if `a` is a Z3 default array expression.
4908 >>> d = Default(K(IntSort(), 10))
4909 >>> is_default(d)
4910 True
4911 """
4912 return is_app_of(a, Z3_OP_ARRAY_DEFAULT)
4913
4914

◆ is_distinct()

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

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

Definition at line 1822 of file z3py.py.

1822def is_distinct(a : Any) -> bool:
1823 """Return `True` if `a` is a Z3 distinct expression.
1824
1825 >>> x, y, z = Ints('x y z')
1826 >>> is_distinct(x == y)
1827 False
1828 >>> is_distinct(Distinct(x, y, z))
1829 True
1830 """
1831 return is_app_of(a, Z3_OP_DISTINCT)
1832
1833

◆ is_div()

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

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

Definition at line 2992 of file z3py.py.

2992def is_div(a : Any) -> bool:
2993 """Return `True` if `a` is an expression of the form b / c.
2994
2995 >>> x, y = Reals('x y')
2996 >>> is_div(x / y)
2997 True
2998 >>> is_div(x + y)
2999 False
3000 >>> x, y = Ints('x y')
3001 >>> is_div(x / y)
3002 False
3003 >>> is_idiv(x / y)
3004 True
3005 """
3006 return is_app_of(a, Z3_OP_DIV)
3007
3008

◆ is_eq()

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

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

Definition at line 1812 of file z3py.py.

1812def is_eq(a : Any) -> bool:
1813 """Return `True` if `a` is a Z3 equality expression.
1814
1815 >>> x, y = Ints('x y')
1816 >>> is_eq(x == y)
1817 True
1818 """
1819 return is_app_of(a, Z3_OP_EQ)
1820
1821

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

1355def is_expr(a):
1356 """Return `True` if `a` is a Z3 expression.
1357
1358 >>> a = Int('a')
1359 >>> is_expr(a)
1360 True
1361 >>> is_expr(a + 1)
1362 True
1363 >>> is_expr(IntSort())
1364 False
1365 >>> is_expr(1)
1366 False
1367 >>> is_expr(IntVal(1))
1368 True
1369 >>> x = Int('x')
1370 >>> is_expr(ForAll(x, x >= 0))
1371 True
1372 >>> is_expr(FPVal(1.0))
1373 True
1374 """
1375 return isinstance(a, ExprRef)
1376
1377

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

◆ is_false()

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

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

Definition at line 1750 of file z3py.py.

1750def is_false(a : Any) -> bool:
1751 """Return `True` if `a` is the Z3 false expression.
1752
1753 >>> p = Bool('p')
1754 >>> is_false(p)
1755 False
1756 >>> is_false(False)
1757 False
1758 >>> is_false(BoolVal(False))
1759 True
1760 """
1761 return is_app_of(a, Z3_OP_FALSE)
1762
1763

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

◆ is_finite_domain()

is_finite_domain ( a)
Return `True` if `a` is a Z3 finite-domain expression.

>>> s = FiniteDomainSort('S', 100)
>>> b = Const('b', s)
>>> is_finite_domain(b)
True
>>> is_finite_domain(Int('x'))
False

Definition at line 8464 of file z3py.py.

8464def is_finite_domain(a):
8465 """Return `True` if `a` is a Z3 finite-domain expression.
8466
8467 >>> s = FiniteDomainSort('S', 100)
8468 >>> b = Const('b', s)
8469 >>> is_finite_domain(b)
8470 True
8471 >>> is_finite_domain(Int('x'))
8472 False
8473 """
8474 return isinstance(a, FiniteDomainRef)
8475
8476

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

8441def is_finite_domain_sort(s):
8442 """Return True if `s` is a Z3 finite-domain sort.
8443
8444 >>> is_finite_domain_sort(FiniteDomainSort('S', 100))
8445 True
8446 >>> is_finite_domain_sort(IntSort())
8447 False
8448 """
8449 return isinstance(s, FiniteDomainSortRef)
8450
8451

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

8518def is_finite_domain_value(a):
8519 """Return `True` if `a` is a Z3 finite-domain value.
8520
8521 >>> s = FiniteDomainSort('S', 100)
8522 >>> b = Const('b', s)
8523 >>> is_finite_domain_value(b)
8524 False
8525 >>> b = FiniteDomainVal(10, s)
8526 >>> b
8527 10
8528 >>> is_finite_domain_value(b)
8529 True
8530 """
8531 return is_finite_domain(a) and _is_numeral(a.ctx, a.as_ast())
8532
8533

◆ is_finite_set()

is_finite_set ( a)
Return True if a is a Z3 finite set expression.
>>> s = FiniteSetSort(IntSort())
>>> is_finite_set(FiniteSetEmpty(s))
True
>>> is_finite_set(IntVal(1))
False

Definition at line 5350 of file z3py.py.

5350def is_finite_set(a):
5351 """Return True if a is a Z3 finite set expression.
5352 >>> s = FiniteSetSort(IntSort())
5353 >>> is_finite_set(FiniteSetEmpty(s))
5354 True
5355 >>> is_finite_set(IntVal(1))
5356 False
5357 """
5358 return isinstance(a, FiniteSetRef)
5359
5360

Referenced by IsMember(), IsSubset(), SetAdd(), SetDel(), SetDifference(), SetIntersect(), and SetUnion().

◆ is_finite_set_sort()

is_finite_set_sort ( s)
Return True if s is a Z3 finite set sort.
>>> is_finite_set_sort(FiniteSetSort(IntSort()))
True
>>> is_finite_set_sort(IntSort())
False

Definition at line 5361 of file z3py.py.

5361def is_finite_set_sort(s):
5362 """Return True if s is a Z3 finite set sort.
5363 >>> is_finite_set_sort(FiniteSetSort(IntSort()))
5364 True
5365 >>> is_finite_set_sort(IntSort())
5366 False
5367 """
5368 return isinstance(s, FiniteSetSortRef)
5369
5370

Referenced by EmptySet().

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

10705def is_fp(a):
10706 """Return `True` if `a` is a Z3 floating-point expression.
10707
10708 >>> b = FP('b', FPSort(8, 24))
10709 >>> is_fp(b)
10710 True
10711 >>> is_fp(b + 1.0)
10712 True
10713 >>> is_fp(Int('x'))
10714 False
10715 """
10716 return isinstance(a, FPRef)
10717
10718

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

10279def is_fp_sort(s):
10280 """Return True if `s` is a Z3 floating-point sort.
10281
10282 >>> is_fp_sort(FPSort(8, 24))
10283 True
10284 >>> is_fp_sort(IntSort())
10285 False
10286 """
10287 return isinstance(s, FPSortRef)
10288
10289

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

10719def is_fp_value(a):
10720 """Return `True` if `a` is a Z3 floating-point numeral value.
10721
10722 >>> b = FP('b', FPSort(8, 24))
10723 >>> is_fp_value(b)
10724 False
10725 >>> b = FPVal(1.0, FPSort(8, 24))
10726 >>> b
10727 1
10728 >>> is_fp_value(b)
10729 True
10730 """
10731 return is_fp(a) and _is_numeral(a.ctx, a.ast)
10732
10733

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

10539def is_fprm(a):
10540 """Return `True` if `a` is a Z3 floating-point rounding mode expression.
10541
10542 >>> rm = RNE()
10543 >>> is_fprm(rm)
10544 True
10545 >>> rm = 1.0
10546 >>> is_fprm(rm)
10547 False
10548 """
10549 return isinstance(a, FPRMRef)
10550
10551

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

10290def is_fprm_sort(s):
10291 """Return True if `s` is a Z3 floating-point rounding mode sort.
10292
10293 >>> is_fprm_sort(FPSort(8, 24))
10294 False
10295 >>> is_fprm_sort(RNE().sort())
10296 True
10297 """
10298 return isinstance(s, FPRMSortRef)
10299
10300# FP Expressions
10301
10302

◆ is_fprm_value()

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

Definition at line 10552 of file z3py.py.

10552def is_fprm_value(a):
10553 """Return `True` if `a` is a Z3 floating-point rounding mode numeral value."""
10554 return is_fprm(a) and _is_numeral(a.ctx, a.ast)
10555
10556# FP Numerals
10557
10558

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

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

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

◆ is_ge()

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

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

Definition at line 3057 of file z3py.py.

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

◆ is_gt()

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

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

Definition at line 3069 of file z3py.py.

3069def is_gt(a : Any) -> bool:
3070 """Return `True` if `a` is an expression of the form b > c.
3071
3072 >>> x, y = Ints('x y')
3073 >>> is_gt(x > y)
3074 True
3075 >>> is_gt(x == y)
3076 False
3077 """
3078 return is_app_of(a, Z3_OP_GT)
3079
3080

◆ is_idiv()

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

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

Definition at line 3009 of file z3py.py.

3009def is_idiv(a : Any) -> bool:
3010 """Return `True` if `a` is an expression of the form b div c.
3011
3012 >>> x, y = Ints('x y')
3013 >>> is_idiv(x / y)
3014 True
3015 >>> is_idiv(x + y)
3016 False
3017 """
3018 return is_app_of(a, Z3_OP_IDIV)
3019
3020

◆ is_implies()

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

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

Definition at line 1788 of file z3py.py.

1788def is_implies(a : Any) -> bool:
1789 """Return `True` if `a` is a Z3 implication expression.
1790
1791 >>> p, q = Bools('p q')
1792 >>> is_implies(Implies(p, q))
1793 True
1794 >>> is_implies(And(p, q))
1795 False
1796 """
1797 return is_app_of(a, Z3_OP_IMPLIES)
1798
1799

◆ is_int()

bool is_int ( a)
Return `True` if `a` is an integer expression.

>>> x = Int('x')
>>> is_int(x + 1)
True
>>> is_int(1)
False
>>> is_int(IntVal(1))
True
>>> y = Real('y')
>>> is_int(y)
False
>>> is_int(y + 1)
False

Definition at line 2850 of file z3py.py.

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

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

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

◆ is_is_int()

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

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

Definition at line 3081 of file z3py.py.

3081def is_is_int(a : Any) -> bool:
3082 """Return `True` if `a` is an expression of the form IsInt(b).
3083
3084 >>> x = Real('x')
3085 >>> is_is_int(IsInt(x))
3086 True
3087 >>> is_is_int(x)
3088 False
3089 """
3090 return is_app_of(a, Z3_OP_IS_INT)
3091
3092

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

4877def is_K(a):
4878 """Return `True` if `a` is a Z3 constant array.
4879
4880 >>> a = K(IntSort(), 10)
4881 >>> is_K(a)
4882 True
4883 >>> a = Array('a', IntSort(), IntSort())
4884 >>> is_K(a)
4885 False
4886 """
4887 return is_app_of(a, Z3_OP_CONST_ARRAY)
4888
4889

◆ is_le()

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

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

Definition at line 3033 of file z3py.py.

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

◆ is_lt()

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

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

Definition at line 3045 of file z3py.py.

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

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

4890def is_map(a):
4891 """Return `True` if `a` is a Z3 map array expression.
4892
4893 >>> f = Function('f', IntSort(), IntSort())
4894 >>> b = Array('b', IntSort(), IntSort())
4895 >>> a = Map(f, b)
4896 >>> a
4897 Map(f, b)
4898 >>> is_map(a)
4899 True
4900 >>> is_map(b)
4901 False
4902 """
4903 return is_app_of(a, Z3_OP_ARRAY_MAP)
4904
4905

Referenced by get_map_func().

◆ is_mod()

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

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

Definition at line 3021 of file z3py.py.

3021def is_mod(a : Any) -> bool:
3022 """Return `True` if `a` is an expression of the form b % c.
3023
3024 >>> x, y = Ints('x y')
3025 >>> is_mod(x % y)
3026 True
3027 >>> is_mod(x + y)
3028 False
3029 """
3030 return is_app_of(a, Z3_OP_MOD)
3031
3032

◆ is_mul()

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

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

Definition at line 2968 of file z3py.py.

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

◆ is_not()

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

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

Definition at line 1800 of file z3py.py.

1800def is_not(a : Any) -> bool:
1801 """Return `True` if `a` is a Z3 not expression.
1802
1803 >>> p = Bool('p')
1804 >>> is_not(p)
1805 False
1806 >>> is_not(Not(p))
1807 True
1808 """
1809 return is_app_of(a, Z3_OP_NOT)
1810
1811

Referenced by mk_not().

◆ is_or()

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

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

Definition at line 1776 of file z3py.py.

1776def is_or(a : Any) -> bool:
1777 """Return `True` if `a` is a Z3 or expression.
1778
1779 >>> p, q = Bools('p q')
1780 >>> is_or(Or(p, q))
1781 True
1782 >>> is_or(And(p, q))
1783 False
1784 """
1785 return is_app_of(a, Z3_OP_OR)
1786
1787

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

2076def is_pattern(a):
2077 """Return `True` if `a` is a Z3 pattern (hint for quantifier instantiation.
2078
2079 >>> f = Function('f', IntSort(), IntSort())
2080 >>> x = Int('x')
2081 >>> q = ForAll(x, f(x) == 0, patterns = [ f(x) ])
2082 >>> q
2083 ForAll(x, f(x) == 0)
2084 >>> q.num_patterns()
2085 1
2086 >>> is_pattern(q.pattern(0))
2087 True
2088 >>> q.pattern(0)
2089 f(Var(0))
2090 """
2091 return isinstance(a, PatternRef)
2092
2093

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

9460def is_probe(p):
9461 """Return `True` if `p` is a Z3 probe.
9462
9463 >>> is_probe(Int('x'))
9464 False
9465 >>> is_probe(Probe('memory'))
9466 True
9467 """
9468 return isinstance(p, Probe)
9469
9470

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

2326def is_quantifier(a):
2327 """Return `True` if `a` is a Z3 quantifier.
2328
2329 >>> f = Function('f', IntSort(), IntSort())
2330 >>> x = Int('x')
2331 >>> q = ForAll(x, f(x) == 0)
2332 >>> is_quantifier(q)
2333 True
2334 >>> is_quantifier(f(x))
2335 False
2336 """
2337 return isinstance(a, QuantifierRef)
2338
2339

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

2920def is_rational_value(a):
2921 """Return `True` if `a` is rational value of sort Real.
2922
2923 >>> is_rational_value(RealVal(1))
2924 True
2925 >>> is_rational_value(RealVal("3/5"))
2926 True
2927 >>> is_rational_value(IntVal(1))
2928 False
2929 >>> is_rational_value(1)
2930 False
2931 >>> n = Real('x') + 1
2932 >>> n.arg(1)
2933 1
2934 >>> is_rational_value(n.arg(1))
2935 True
2936 >>> is_rational_value(Real('x'))
2937 False
2938 """
2939 return is_arith(a) and a.is_real() and _is_numeral(a.ctx, a.as_ast())
2940
2941

◆ is_re()

is_re ( s)

Definition at line 12093 of file z3py.py.

12093def is_re(s):
12094 return isinstance(s, ReRef)
12095
12096

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

2869def is_real(a):
2870 """Return `True` if `a` is a real expression.
2871
2872 >>> x = Int('x')
2873 >>> is_real(x + 1)
2874 False
2875 >>> y = Real('y')
2876 >>> is_real(y)
2877 True
2878 >>> is_real(y + 1)
2879 True
2880 >>> is_real(1)
2881 False
2882 >>> is_real(RealVal(1))
2883 True
2884 """
2885 return is_arith(a) and a.is_real()
2886
2887

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

5139def is_select(a):
5140 """Return `True` if `a` is a Z3 array select application.
5141
5142 >>> a = Array('a', IntSort(), IntSort())
5143 >>> is_select(a)
5144 False
5145 >>> i = Int('i')
5146 >>> is_select(a[i])
5147 True
5148 """
5149 return is_app_of(a, Z3_OP_SELECT)
5150
5151

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

11765def is_seq(a):
11766 """Return `True` if `a` is a Z3 sequence expression.
11767 >>> print (is_seq(Unit(IntVal(0))))
11768 True
11769 >>> print (is_seq(StringVal("abc")))
11770 True
11771 """
11772 return isinstance(a, SeqRef)
11773
11774

Referenced by Concat(), and Extract().

◆ is_sort()

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

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

Definition at line 682 of file z3py.py.

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

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

◆ is_store()

is_store ( a)
Return `True` if `a` is a Z3 array store application.

>>> a = Array('a', IntSort(), IntSort())
>>> is_store(a)
False
>>> is_store(Store(a, 0, 1))
True

Definition at line 5152 of file z3py.py.

5152def is_store(a):
5153 """Return `True` if `a` is a Z3 array store application.
5154
5155 >>> a = Array('a', IntSort(), IntSort())
5156 >>> is_store(a)
5157 False
5158 >>> is_store(Store(a, 0, 1))
5159 True
5160 """
5161 return is_app_of(a, Z3_OP_STORE)
5162

◆ is_string()

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

Definition at line 11775 of file z3py.py.

11775def is_string(a: Any) -> bool:
11776 """Return `True` if `a` is a Z3 string expression.
11777 >>> print (is_string(StringVal("ab")))
11778 True
11779 """
11780 return isinstance(a, SeqRef) and a.is_string()
11781
11782

◆ is_string_value()

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

Definition at line 11783 of file z3py.py.

11783def is_string_value(a: Any) -> bool:
11784 """return 'True' if 'a' is a Z3 string constant expression.
11785 >>> print (is_string_value(StringVal("a")))
11786 True
11787 >>> print (is_string_value(StringVal("a") + StringVal("b")))
11788 False
11789 """
11790 return isinstance(a, SeqRef) and a.is_string_value()
11791

◆ is_sub()

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

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

Definition at line 2980 of file z3py.py.

2980def is_sub(a : Any) -> bool:
2981 """Return `True` if `a` is an expression of the form b - c.
2982
2983 >>> x, y = Ints('x y')
2984 >>> is_sub(x - y)
2985 True
2986 >>> is_sub(x + y)
2987 False
2988 """
2989 return is_app_of(a, Z3_OP_SUB)
2990
2991

◆ is_to_int()

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

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

Definition at line 3108 of file z3py.py.

3108def is_to_int(a : Any) -> bool:
3109 """Return `True` if `a` is an expression of the form ToInt(b).
3110
3111 >>> x = Real('x')
3112 >>> n = ToInt(x)
3113 >>> n
3114 ToInt(x)
3115 >>> is_to_int(n)
3116 True
3117 >>> is_to_int(x)
3118 False
3119 """
3120 return is_app_of(a, Z3_OP_TO_INT)
3121
3122

◆ is_to_real()

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

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

Definition at line 3093 of file z3py.py.

3093def is_to_real(a : Any) -> bool:
3094 """Return `True` if `a` is an expression of the form ToReal(b).
3095
3096 >>> x = Int('x')
3097 >>> n = ToReal(x)
3098 >>> n
3099 ToReal(x)
3100 >>> is_to_real(n)
3101 True
3102 >>> is_to_real(x)
3103 False
3104 """
3105 return is_app_of(a, Z3_OP_TO_REAL)
3106
3107

◆ is_true()

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

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

Definition at line 1732 of file z3py.py.

1732def is_true(a : Any) -> bool:
1733 """Return `True` if `a` is the Z3 true expression.
1734
1735 >>> p = Bool('p')
1736 >>> is_true(p)
1737 False
1738 >>> is_true(simplify(p == p))
1739 True
1740 >>> x = Real('x')
1741 >>> is_true(x == 0)
1742 False
1743 >>> # True is a Python Boolean expression
1744 >>> is_true(True)
1745 False
1746 """
1747 return is_app_of(a, Z3_OP_TRUE)
1748
1749

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

◆ is_var()

is_var ( a)
Return `True` if `a` is variable.

Z3 uses de-Bruijn indices for representing bound variables in
quantifiers.

>>> x = Int('x')
>>> is_var(x)
False
>>> is_const(x)
True
>>> f = Function('f', IntSort(), IntSort())
>>> # Z3 replaces x with bound variables when ForAll is executed.
>>> q = ForAll(x, f(x) == x)
>>> b = q.body()
>>> b
f(Var(0)) == Var(0)
>>> b.arg(1)
Var(0)
>>> is_var(b.arg(1))
True

Definition at line 1423 of file z3py.py.

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

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

3566def IsInt(a):
3567 """ Return the Z3 predicate IsInt(a).
3568
3569 >>> x = Real('x')
3570 >>> IsInt(x + "1/2")
3571 IsInt(x + 1/2)
3572 >>> solve(IsInt(x + "1/2"), x > 0, x < 1)
3573 [x = 1/2]
3574 >>> solve(IsInt(x + "1/2"), x > 0, x < 1, x != "1/2")
3575 no solution
3576 """
3577 if z3_debug():
3578 _z3_assert(a.is_real(), "Z3 real expression expected.")
3579 ctx = a.ctx
3580 return BoolRef(Z3_mk_is_int(ctx.ref(), a.as_ast()), ctx)
3581
3582
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 5276 of file z3py.py.

5276def IsMember(e, s):
5277 """ Check if e is a member of set s
5278 >>> a = Const('a', SetSort(IntSort()))
5279 >>> IsMember(1, a)
5280 a[1]
5281 """
5282 ctx = _ctx_from_ast_arg_list([s, e])
5283 e = _py2expr(e, ctx)
5284 if is_finite_set(s):
5285 return FiniteSetIsMember(e, s)
5286 return BoolRef(Z3_mk_set_member(ctx.ref(), e.as_ast(), s.as_ast()), ctx)
5287
5288
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 5289 of file z3py.py.

5289def IsSubset(a, b):
5290 """ Check if a is a subset of b
5291 >>> a = Const('a', SetSort(IntSort()))
5292 >>> b = Const('b', SetSort(IntSort()))
5293 >>> IsSubset(a, b)
5294 subset(a, b)
5295 """
5296 ctx = _ctx_from_ast_arg_list([a, b])
5297 if is_finite_set(a):
5298 return FiniteSetIsSubset(a, b)
5299 return BoolRef(Z3_mk_set_subset(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
5300
5301
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 5087 of file z3py.py.

5087def K(dom, v):
5088 """Return a Z3 constant array expression.
5089
5090 >>> a = K(IntSort(), 10)
5091 >>> a
5092 K(Int, 10)
5093 >>> a.sort()
5094 Array(Int, Int)
5095 >>> i = Int('i')
5096 >>> a[i]
5097 K(Int, 10)[i]
5098 >>> simplify(a[i])
5099 10
5100 """
5101 if z3_debug():
5102 _z3_assert(is_sort(dom), "Z3 sort expected")
5103 ctx = dom.ctx
5104 if not is_expr(v):
5105 v = _py2expr(v, ctx)
5106 return ArrayRef(Z3_mk_const_array(ctx.ref(), dom.ast, v.as_ast()), ctx)
5107
5108
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 2414 of file z3py.py.

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

11968def LastIndexOf(s, substr):
11969 """Retrieve the last index of substring within a string"""
11970 ctx = None
11971 ctx = _get_ctx2(s, substr, ctx)
11972 s = _coerce_seq(s, ctx)
11973 substr = _coerce_seq(substr, ctx)
11974 return ArithRef(Z3_mk_seq_last_index(s.ctx_ref(), s.as_ast(), substr.as_ast()), s.ctx)
11975
11976
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 11977 of file z3py.py.

11977def Length(s):
11978 """Obtain the length of a sequence 's'
11979 >>> l = Length(StringVal("abc"))
11980 >>> simplify(l)
11981 3
11982 """
11983 s = _coerce_seq(s)
11984 return ArithRef(Z3_mk_seq_length(s.ctx_ref(), s.as_ast()), s.ctx)
11985
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 12265 of file z3py.py.

12265def LinearOrder(a, index):
12266 return FuncDeclRef(Z3_mk_linear_order(a.ctx_ref(), a.ast, index), a.ctx)
12267
12268
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 12215 of file z3py.py.

12215def Loop(re, lo, hi=0):
12216 """Create the regular expression accepting between a lower and upper bound repetitions
12217 >>> re = Loop(Re("a"), 1, 3)
12218 >>> print(simplify(InRe("aa", re)))
12219 True
12220 >>> print(simplify(InRe("aaaa", re)))
12221 False
12222 >>> print(simplify(InRe("", re)))
12223 False
12224 """
12225 if z3_debug():
12226 _z3_assert(is_expr(re), "expression expected")
12227 return ReRef(Z3_mk_re_loop(re.ctx_ref(), re.as_ast(), lo, hi), re.ctx)
12228
12229
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 4499 of file z3py.py.

4499def LShR(a, b):
4500 """Create the Z3 expression logical right shift.
4501
4502 Use the operator >> for the arithmetical right shift.
4503
4504 >>> x, y = BitVecs('x y', 32)
4505 >>> LShR(x, y)
4506 LShR(x, y)
4507 >>> (x >> y).sexpr()
4508 '(bvashr x y)'
4509 >>> LShR(x, y).sexpr()
4510 '(bvlshr x y)'
4511 >>> BitVecVal(4, 3)
4512 4
4513 >>> BitVecVal(4, 3).as_signed_long()
4514 -4
4515 >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
4516 -2
4517 >>> simplify(BitVecVal(4, 3) >> 1)
4518 6
4519 >>> simplify(LShR(BitVecVal(4, 3), 1))
4520 2
4521 >>> simplify(BitVecVal(2, 3) >> 1)
4522 1
4523 >>> simplify(LShR(BitVecVal(2, 3), 1))
4524 1
4525 """
4526 _check_bv_args(a, b)
4527 a, b = _coerce_exprs(a, b)
4528 return BitVecRef(Z3_mk_bvlshr(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4529
4530
Z3_ast Z3_API Z3_mk_bvlshr(Z3_context c, Z3_ast t1, Z3_ast t2)
Logical shift right.

◆ main_ctx()

Context main_ctx ( )
Return a reference to the global Z3 context.

>>> x = Real('x')
>>> x.ctx == main_ctx()
True
>>> c = Context()
>>> c == main_ctx()
False
>>> x2 = Real('x', c)
>>> x2.ctx == c
True
>>> eq(x, x2)
False

Definition at line 266 of file z3py.py.

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

Referenced by _get_ctx().

◆ Map()

Map ( f,
* args )
Return a Z3 map array expression.

>>> f = Function('f', IntSort(), IntSort(), IntSort())
>>> a1 = Array('a1', IntSort(), IntSort())
>>> a2 = Array('a2', IntSort(), IntSort())
>>> b  = Map(f, a1, a2)
>>> b
Map(f, a1, a2)
>>> prove(b[0] == f(a1[0], a2[0]))
proved

Definition at line 5064 of file z3py.py.

5064def Map(f, *args):
5065 """Return a Z3 map array expression.
5066
5067 >>> f = Function('f', IntSort(), IntSort(), IntSort())
5068 >>> a1 = Array('a1', IntSort(), IntSort())
5069 >>> a2 = Array('a2', IntSort(), IntSort())
5070 >>> b = Map(f, a1, a2)
5071 >>> b
5072 Map(f, a1, a2)
5073 >>> prove(b[0] == f(a1[0], a2[0]))
5074 proved
5075 """
5076 args = _get_args(args)
5077 if z3_debug():
5078 _z3_assert(len(args) > 0, "At least one Z3 array expression expected")
5079 _z3_assert(is_func_decl(f), "First argument must be a Z3 function declaration")
5080 _z3_assert(all([is_array(a) for a in args]), "Z3 array expected expected")
5081 _z3_assert(len(args) == f.arity(), "Number of arguments mismatch")
5082 _args, sz = _to_ast_array(args)
5083 ctx = f.ctx
5084 return ArrayRef(Z3_mk_map(ctx.ref(), f.ast, sz, _args), ctx)
5085
5086
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 1977 of file z3py.py.

1977def mk_not(a):
1978 if is_not(a):
1979 return a.arg(0)
1980 else:
1981 return Not(a)
1982
1983

◆ Model()

Model ( ctx = None,
eval = {} )

Definition at line 7337 of file z3py.py.

7337def Model(ctx=None, eval = {}):
7338 ctx = _get_ctx(ctx)
7339 mdl = ModelRef(Z3_mk_model(ctx.ref()), ctx)
7340 for k, v in eval.items():
7341 mdl.update_value(k, v)
7342 return mdl
7343
7344
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 2094 of file z3py.py.

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

1958def Not(a, ctx=None):
1959 """Create a Z3 not expression or probe.
1960
1961 >>> p = Bool('p')
1962 >>> Not(Not(p))
1963 Not(Not(p))
1964 >>> simplify(Not(Not(p)))
1965 p
1966 """
1967 ctx = _get_ctx(_ctx_from_ast_arg_list([a], ctx))
1968 if is_probe(a):
1969 # Not is also used to build probes
1970 return Probe(Z3_probe_not(ctx.ref(), a.probe), ctx)
1971 else:
1972 s = BoolSort(ctx)
1973 a = s.cast(a)
1974 return BoolRef(Z3_mk_not(ctx.ref(), a.as_ast()), ctx)
1975
1976
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().

◆ num_simplifiers()

num_simplifiers ( ctx = None)
Return the number of simplifiers supported by the given context.

Definition at line 8934 of file z3py.py.

8934def num_simplifiers(ctx=None):
8935 """Return the number of simplifiers supported by the given context."""
8936 return Z3_get_num_simplifiers(_get_ctx(ctx).ref())
8937
8938
unsigned Z3_API Z3_get_num_simplifiers(Z3_context c)
Return the number of builtin simplifiers available in Z3.

◆ on_clause_eh()

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

Definition at line 12305 of file z3py.py.

12305def on_clause_eh(ctx, p, n, dep, clause):
12306 onc = _my_hacky_class
12307 p = _to_expr_ref(to_Ast(p), onc.ctx)
12308 clause = AstVector(to_AstVectorObj(clause), onc.ctx)
12309 deps = [dep[i] for i in range(n)]
12310 onc.on_clause(p, deps, clause)
12311

◆ open_log()

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

Definition at line 122 of file z3py.py.

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

◆ Option()

Option ( re)
Create the regular expression that optionally accepts the argument.
>>> re = Option(Re("a"))
>>> print(simplify(InRe("a", re)))
True
>>> print(simplify(InRe("", re)))
True
>>> print(simplify(InRe("aa", re)))
False

Definition at line 12180 of file z3py.py.

12180def Option(re):
12181 """Create the regular expression that optionally accepts the argument.
12182 >>> re = Option(Re("a"))
12183 >>> print(simplify(InRe("a", re)))
12184 True
12185 >>> print(simplify(InRe("", re)))
12186 True
12187 >>> print(simplify(InRe("aa", re)))
12188 False
12189 """
12190 if z3_debug():
12191 _z3_assert(is_expr(re), "expression expected")
12192 return ReRef(Z3_mk_re_option(re.ctx_ref(), re.as_ast()), re.ctx)
12193
12194
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 2025 of file z3py.py.

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

9153def OrElse(*ts, **ks):
9154 """Return a tactic that applies the tactics in `*ts` until one of them succeeds (it doesn't fail).
9155
9156 >>> x = Int('x')
9157 >>> t = OrElse(Tactic('split-clause'), Tactic('skip'))
9158 >>> # Tactic split-clause fails if there is no clause in the given goal.
9159 >>> t(x == 0)
9160 [[x == 0]]
9161 >>> t(Or(x == 0, x == 1))
9162 [[x == 0], [x == 1]]
9163 """
9164 if z3_debug():
9165 _z3_assert(len(ts) >= 2, "At least two arguments expected")
9166 ctx = ks.get("ctx", None)
9167 num = len(ts)
9168 r = ts[0]
9169 for i in range(num - 1):
9170 r = _or_else(r, ts[i + 1], ctx)
9171 return r
9172
9173

◆ ParAndThen()

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

Definition at line 9209 of file z3py.py.

9209def ParAndThen(t1, t2, ctx=None):
9210 """Alias for ParThen(t1, t2, ctx)."""
9211 return ParThen(t1, t2, ctx)
9212
9213

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

9174def ParOr(*ts, **ks):
9175 """Return a tactic that applies the tactics in `*ts` in parallel until one of them succeeds (it doesn't fail).
9176
9177 >>> x = Int('x')
9178 >>> t = ParOr(Tactic('simplify'), Tactic('fail'))
9179 >>> t(x + 1 == 2)
9180 [[x == 1]]
9181 """
9182 if z3_debug():
9183 _z3_assert(len(ts) >= 2, "At least two arguments expected")
9184 ctx = _get_ctx(ks.get("ctx", None))
9185 ts = [_to_tactic(t, ctx) for t in ts]
9186 sz = len(ts)
9187 _args = (TacticObj * sz)()
9188 for i in range(sz):
9189 _args[i] = ts[i].tactic
9190 return Tactic(Z3_tactic_par_or(ctx.ref(), sz, _args), ctx)
9191
9192
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 10089 of file z3py.py.

10089def parse_smt2_file(f, sorts={}, decls={}, ctx=None):
10090 """Parse a file in SMT 2.0 format using the given sorts and decls.
10091
10092 This function is similar to parse_smt2_string().
10093 """
10094 ctx = _get_ctx(ctx)
10095 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
10096 dsz, dnames, ddecls = _dict2darray(decls, ctx)
10097 return AstVector(Z3_parse_smtlib2_file(ctx.ref(), f, ssz, snames, ssorts, dsz, dnames, ddecls), ctx)
10098
10099
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 10068 of file z3py.py.

10068def parse_smt2_string(s, sorts={}, decls={}, ctx=None):
10069 """Parse a string in SMT 2.0 format using the given sorts and decls.
10070
10071 The arguments sorts and decls are Python dictionaries used to initialize
10072 the symbol table used for the SMT 2.0 parser.
10073
10074 >>> parse_smt2_string('(declare-const x Int) (assert (> x 0)) (assert (< x 10))')
10075 [x > 0, x < 10]
10076 >>> x, y = Ints('x y')
10077 >>> f = Function('f', IntSort(), IntSort())
10078 >>> parse_smt2_string('(assert (> (+ foo (g bar)) 0))', decls={ 'foo' : x, 'bar' : y, 'g' : f})
10079 [x + f(y) > 0]
10080 >>> parse_smt2_string('(declare-const a U) (assert (> a 0))', sorts={ 'U' : IntSort() })
10081 [a > 0]
10082 """
10083 ctx = _get_ctx(ctx)
10084 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
10085 dsz, dnames, ddecls = _dict2darray(decls, ctx)
10086 return AstVector(Z3_parse_smtlib2_string(ctx.ref(), s, ssz, snames, ssorts, dsz, dnames, ddecls), ctx)
10087
10088
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 9193 of file z3py.py.

9193def ParThen(t1, t2, ctx=None):
9194 """Return a tactic that applies t1 and then t2 to every subgoal produced by t1.
9195 The subgoals are processed in parallel.
9196
9197 >>> x, y = Ints('x y')
9198 >>> t = ParThen(Tactic('split-clause'), Tactic('propagate-values'))
9199 >>> t(And(Or(x == 1, x == 2), y == x + 1))
9200 [[x == 1, y == 2], [x == 2, y == 3]]
9201 """
9202 t1 = _to_tactic(t1, ctx)
9203 t2 = _to_tactic(t2, ctx)
9204 if z3_debug():
9205 _z3_assert(t1.ctx == t2.ctx, "Context mismatch")
9206 return Tactic(Z3_tactic_par_and_then(t1.ctx.ref(), t1.tactic, t2.tactic), t1.ctx)
9207
9208
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 12261 of file z3py.py.

12261def PartialOrder(a, index):
12262 return FuncDeclRef(Z3_mk_partial_order(a.ctx_ref(), a.ast, index), a.ctx)
12263
12264
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 9845 of file z3py.py.

9845def PbEq(args, k, ctx=None):
9846 """Create a Pseudo-Boolean equality k constraint.
9847
9848 >>> a, b, c = Bools('a b c')
9849 >>> f = PbEq(((a,1),(b,3),(c,2)), 3)
9850 """
9851 _z3_check_cint_overflow(k, "k")
9852 ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
9853 return BoolRef(Z3_mk_pbeq(ctx.ref(), sz, _args, _coeffs, k), ctx)
9854
9855
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 9834 of file z3py.py.

9834def PbGe(args, k):
9835 """Create a Pseudo-Boolean inequality k constraint.
9836
9837 >>> a, b, c = Bools('a b c')
9838 >>> f = PbGe(((a,1),(b,3),(c,2)), 3)
9839 """
9840 _z3_check_cint_overflow(k, "k")
9841 ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
9842 return BoolRef(Z3_mk_pbge(ctx.ref(), sz, _args, _coeffs, k), ctx)
9843
9844
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 9823 of file z3py.py.

9823def PbLe(args, k):
9824 """Create a Pseudo-Boolean inequality k constraint.
9825
9826 >>> a, b, c = Bools('a b c')
9827 >>> f = PbLe(((a,1),(b,3),(c,2)), 3)
9828 """
9829 _z3_check_cint_overflow(k, "k")
9830 ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
9831 return BoolRef(Z3_mk_pble(ctx.ref(), sz, _args, _coeffs, k), ctx)
9832
9833
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 12273 of file z3py.py.

12273def PiecewiseLinearOrder(a, index):
12274 return FuncDeclRef(Z3_mk_piecewise_linear_order(a.ctx_ref(), a.ast, index), a.ctx)
12275
12276
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 12165 of file z3py.py.

12165def Plus(re):
12166 """Create the regular expression accepting one or more repetitions of argument.
12167 >>> re = Plus(Re("a"))
12168 >>> print(simplify(InRe("aa", re)))
12169 True
12170 >>> print(simplify(InRe("ab", re)))
12171 False
12172 >>> print(simplify(InRe("", re)))
12173 False
12174 """
12175 if z3_debug():
12176 _z3_assert(is_expr(re), "expression expected")
12177 return ReRef(Z3_mk_re_plus(re.ctx_ref(), re.as_ast()), re.ctx)
12178
12179
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 11884 of file z3py.py.

11884def PrefixOf(a, b):
11885 """Check if 'a' is a prefix of 'b'
11886 >>> s1 = PrefixOf("ab", "abc")
11887 >>> simplify(s1)
11888 True
11889 >>> s2 = PrefixOf("bc", "abc")
11890 >>> simplify(s2)
11891 False
11892 """
11893 ctx = _get_ctx2(a, b)
11894 a = _coerce_seq(a, ctx)
11895 b = _coerce_seq(b, ctx)
11896 return BoolRef(Z3_mk_seq_prefix(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
11897
11898
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 9489 of file z3py.py.

9489def probe_description(name, ctx=None):
9490 """Return a short description for the probe named `name`.
9491
9492 >>> d = probe_description('memory')
9493 """
9494 ctx = _get_ctx(ctx)
9495 return Z3_probe_get_descr(ctx.ref(), name)
9496
9497
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 9478 of file z3py.py.

9478def probes(ctx=None):
9479 """Return a list of all available probes in Z3.
9480
9481 >>> l = probes()
9482 >>> l.count('memory') == 1
9483 True
9484 """
9485 ctx = _get_ctx(ctx)
9486 return [Z3_get_probe_name(ctx.ref(), i) for i in range(Z3_get_num_probes(ctx.ref()))]
9487
9488
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 9730 of file z3py.py.

9730def Product(*args):
9731 """Create the product of the Z3 expressions.
9732
9733 >>> a, b, c = Ints('a b c')
9734 >>> Product(a, b, c)
9735 a*b*c
9736 >>> Product([a, b, c])
9737 a*b*c
9738 >>> A = IntVector('a', 5)
9739 >>> Product(A)
9740 a__0*a__1*a__2*a__3*a__4
9741 """
9742 args = _get_args(args)
9743 if len(args) == 0:
9744 return 1
9745 ctx = _ctx_from_ast_arg_list(args)
9746 if ctx is None:
9747 return _reduce(lambda a, b: a * b, args, 1)
9748 args = _coerce_expr_list(args, ctx)
9749 if is_bv(args[0]) or isinstance(args[0], FiniteFieldRef):
9750 return _reduce(lambda a, b: a * b, args, 1)
9751 else:
9752 _args, sz = _to_ast_array(args)
9753 return ArithRef(Z3_mk_mul(ctx.ref(), sz, _args), ctx)
9754
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 12470 of file z3py.py.

12470def PropagateFunction(name, *sig):
12471 """Create a function that gets tracked by user propagator.
12472 Every term headed by this function symbol is tracked.
12473 If a term is fixed and the fixed callback is registered a
12474 callback is invoked that the term headed by this function is fixed.
12475 """
12476 sig = _get_args(sig)
12477 if z3_debug():
12478 _z3_assert(len(sig) > 0, "At least two arguments expected")
12479 arity = len(sig) - 1
12480 rng = sig[arity]
12481 if z3_debug():
12482 _z3_assert(is_sort(rng), "Z3 sort expected")
12483 dom = (Sort * arity)()
12484 for i in range(arity):
12485 if z3_debug():
12486 _z3_assert(is_sort(sig[i]), "Z3 sort expected")
12487 dom[i] = sig[i].ast
12488 ctx = rng.ctx
12489 return FuncDeclRef(Z3_solver_propagate_declare(ctx.ref(), to_symbol(name, ctx), arity, dom, rng.ast), ctx)
12490
12491
12492
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 9917 of file z3py.py.

9917def prove(claim, show=False, **keywords):
9918 """Try to prove the given claim.
9919
9920 This is a simple function for creating demonstrations. It tries to prove
9921 `claim` by showing the negation is unsatisfiable.
9922
9923 >>> p, q = Bools('p q')
9924 >>> prove(Not(And(p, q)) == Or(Not(p), Not(q)))
9925 proved
9926 """
9927 if z3_debug():
9928 _z3_assert(is_bool(claim), "Z3 Boolean expression expected")
9929 s = Solver()
9930 s.set(**keywords)
9931 s.add(Not(claim))
9932 if show:
9933 print(s)
9934 r = s.check()
9935 if r == unsat:
9936 print("proved")
9937 elif r == unknown:
9938 print("failed to prove")
9939 print(s.model())
9940 else:
9941 print("counterexample")
9942 print(s.model())
9943
9944

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

3405def Q(a, b, ctx=None):
3406 """Return a Z3 rational a/b.
3407
3408 If `ctx=None`, then the global context is used.
3409
3410 >>> Q(3,5)
3411 3/5
3412 >>> Q(3,5).sort()
3413 Real
3414 """
3415 return simplify(RatVal(a, b, ctx=ctx))
3416
3417

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

12230def Range(lo, hi, ctx=None):
12231 """Create the range regular expression over two sequences of length 1
12232 >>> range = Range("a","z")
12233 >>> print(simplify(InRe("b", range)))
12234 True
12235 >>> print(simplify(InRe("bb", range)))
12236 False
12237 """
12238 lo = _coerce_seq(lo, ctx)
12239 hi = _coerce_seq(hi, ctx)
12240 if z3_debug():
12241 _z3_assert(is_expr(lo), "expression expected")
12242 _z3_assert(is_expr(hi), "expression expected")
12243 return ReRef(Z3_mk_re_range(lo.ctx_ref(), lo.ast, hi.ast), lo.ctx)
12244
Z3_ast Z3_API Z3_mk_re_range(Z3_context c, Z3_ast lo, Z3_ast hi)
Create the range regular expression over two sequences of length 1.

◆ RatVal()

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

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

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

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

Definition at line 3385 of file z3py.py.

3385def RatVal(a, b, ctx=None):
3386 """Return a Z3 rational a/b.
3387
3388 If `ctx=None`, then the global context is used.
3389
3390 Note: Division by zero (b == 0) is allowed in Z3 symbolic expressions.
3391 Z3 can reason about such expressions symbolically.
3392
3393 >>> RatVal(3,5)
3394 3/5
3395 >>> RatVal(3,5).sort()
3396 Real
3397 """
3398 if z3_debug():
3399 _z3_assert(_is_int(a) or isinstance(a, str), "First argument cannot be converted into an integer")
3400 _z3_assert(_is_int(b) or isinstance(b, str), "Second argument cannot be converted into an integer")
3401 # Division by 0 is intentionally allowed - Z3 handles it symbolically
3402 return simplify(RealVal(a, ctx) / RealVal(b, ctx))
3403
3404

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

12058def Re(s, ctx=None):
12059 """The regular expression that accepts sequence 's'
12060 >>> s1 = Re("ab")
12061 >>> s2 = Re(StringVal("ab"))
12062 >>> s3 = Re(Unit(BoolVal(True)))
12063 """
12064 s = _coerce_seq(s, ctx)
12065 return ReRef(Z3_mk_seq_to_re(s.ctx_ref(), s.as_ast()), s.ctx)
12066
12067
12068# Regular expressions
12069
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 3471 of file z3py.py.

3471def Real(name, ctx=None):
3472 """Return a real constant named `name`. If `ctx=None`, then the global context is used.
3473
3474 >>> x = Real('x')
3475 >>> is_real(x)
3476 True
3477 >>> is_real(x + 1)
3478 True
3479 """
3480 ctx = _get_ctx(ctx)
3481 return ArithRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), RealSort(ctx).ast), ctx)
3482
3483

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

3484def Reals(names, ctx=None):
3485 """Return a tuple of real constants.
3486
3487 >>> x, y, z = Reals('x y z')
3488 >>> Sum(x, y, z)
3489 x + y + z
3490 >>> Sum(x, y, z).sort()
3491 Real
3492 """
3493 ctx = _get_ctx(ctx)
3494 if isinstance(names, str):
3495 names = names.split(" ")
3496 return [Real(name, ctx) for name in names]
3497
3498

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

3325def RealSort(ctx=None):
3326 """Return the real sort in the given context. If `ctx=None`, then the global context is used.
3327
3328 >>> RealSort()
3329 Real
3330 >>> x = Const('x', RealSort())
3331 >>> is_real(x)
3332 True
3333 >>> is_int(x)
3334 False
3335 >>> x.sort() == RealSort()
3336 True
3337 """
3338 ctx = _get_ctx(ctx)
3339 return ArithSortRef(Z3_mk_real_sort(ctx.ref()), ctx)
3340
3341
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 3366 of file z3py.py.

3366def RealVal(val, ctx=None):
3367 """Return a Z3 real value.
3368
3369 `val` may be a Python int, long, float or string representing a number in decimal or rational notation.
3370 If `ctx=None`, then the global context is used.
3371
3372 >>> RealVal(1)
3373 1
3374 >>> RealVal(1).sort()
3375 Real
3376 >>> RealVal("3/5")
3377 3/5
3378 >>> RealVal("1.5")
3379 3/2
3380 """
3381 ctx = _get_ctx(ctx)
3382 return RatNumRef(Z3_mk_numeral(ctx.ref(), str(val), RealSort(ctx).ast), ctx)
3383
3384

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

◆ RealVar()

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

>>> RealVar(0)
Var(0)

Definition at line 1600 of file z3py.py.

1600def RealVar(idx: int, ctx=None) -> ExprRef:
1601 """
1602 Create a real free variable. Free variables are used to create quantified formulas.
1603 They are also used to create polynomials.
1604
1605 >>> RealVar(0)
1606 Var(0)
1607 """
1608 return Var(idx, RealSort(ctx))
1609

Referenced by RealVarVector().

◆ RealVarVector()

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

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

Definition at line 1610 of file z3py.py.

1610def RealVarVector(n: int, ctx= None):
1611 """
1612 Create a list of Real free variables.
1613 The variables have ids: 0, 1, ..., n-1
1614
1615 >>> x0, x1, x2, x3 = RealVarVector(4)
1616 >>> x2
1617 Var(2)
1618 """
1619 return [RealVar(i, ctx) for i in range(n)]
1620

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

3499def RealVector(prefix, sz, ctx=None):
3500 """Return a list of real constants of size `sz`.
3501
3502 >>> X = RealVector('x', 3)
3503 >>> X
3504 [x__0, x__1, x__2]
3505 >>> Sum(X)
3506 x__0 + x__1 + x__2
3507 >>> Sum(X).sort()
3508 Real
3509 """
3510 ctx = _get_ctx(ctx)
3511 return [Real("%s__%s" % (prefix, i), ctx) for i in range(sz)]
3512
3513

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

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

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

9242def Repeat(t, max=4294967295, ctx=None):
9243 """Return a tactic that keeps applying `t` until the goal is not modified anymore
9244 or the maximum number of iterations `max` is reached.
9245
9246 >>> x, y = Ints('x y')
9247 >>> c = And(Or(x == 0, x == 1), Or(y == 0, y == 1), x > y)
9248 >>> t = Repeat(OrElse(Tactic('split-clause'), Tactic('skip')))
9249 >>> r = t(c)
9250 >>> for subgoal in r: print(subgoal)
9251 [x == 0, y == 0, x > y]
9252 [x == 0, y == 1, x > y]
9253 [x == 1, y == 0, x > y]
9254 [x == 1, y == 1, x > y]
9255 >>> t = Then(t, Tactic('propagate-values'))
9256 >>> t(c)
9257 [[x == 1, y == 0]]
9258 """
9259 t = _to_tactic(t, ctx)
9260 return Tactic(Z3_tactic_repeat(t.ctx.ref(), t.tactic, max), t.ctx)
9261
9262
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 4621 of file z3py.py.

4621def RepeatBitVec(n, a):
4622 """Return an expression representing `n` copies of `a`.
4623
4624 >>> x = BitVec('x', 8)
4625 >>> n = RepeatBitVec(4, x)
4626 >>> n
4627 RepeatBitVec(4, x)
4628 >>> n.size()
4629 32
4630 >>> v0 = BitVecVal(10, 4)
4631 >>> print("%.x" % v0.as_long())
4632 a
4633 >>> v = simplify(RepeatBitVec(4, v0))
4634 >>> v.size()
4635 16
4636 >>> print("%.x" % v.as_long())
4637 aaaa
4638 """
4639 if z3_debug():
4640 _z3_assert(_is_int(n), "First argument must be an integer")
4641 _z3_assert(is_bv(a), "Second argument must be a Z3 bit-vector expression")
4642 return BitVecRef(Z3_mk_repeat(a.ctx_ref(), n, a.as_ast()), a.ctx)
4643
4644
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 11933 of file z3py.py.

11933def Replace(s, src, dst):
11934 """Replace the first occurrence of 'src' by 'dst' in 's'
11935 >>> r = Replace("aaa", "a", "b")
11936 >>> simplify(r)
11937 "baa"
11938 """
11939 ctx = _get_ctx2(dst, s)
11940 if ctx is None and is_expr(src):
11941 ctx = src.ctx
11942 src = _coerce_seq(src, ctx)
11943 dst = _coerce_seq(dst, ctx)
11944 s = _coerce_seq(s, ctx)
11945 return SeqRef(Z3_mk_seq_replace(src.ctx_ref(), s.as_ast(), src.as_ast(), dst.as_ast()), s.ctx)
11946
11947
Z3_ast Z3_API Z3_mk_seq_replace(Z3_context c, Z3_ast s, Z3_ast src, Z3_ast dst)
Replace the first occurrence of src with dst in s.

◆ reset_params()

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

Definition at line 322 of file z3py.py.

322def reset_params() -> None:
323 """Reset all global (or module) parameters.
324 """
326
327
void Z3_API Z3_global_param_reset_all(void)
Restore the value of all global (and module) parameters. This command will not affect already created...

◆ ReSort()

ReSort ( s)

Definition at line 12077 of file z3py.py.

12077def ReSort(s):
12078 if is_ast(s):
12079 return ReSortRef(Z3_mk_re_sort(s.ctx.ref(), s.ast), s.ctx)
12080 if s is None or isinstance(s, Context):
12081 ctx = _get_ctx(s)
12082 return ReSortRef(Z3_mk_re_sort(ctx.ref(), Z3_mk_string_sort(ctx.ref())), s.ctx)
12083 raise Z3Exception("Regular expression sort constructor expects either a string or a context or no argument")
12084
12085
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 10504 of file z3py.py.

10504def RNA(ctx=None):
10505 ctx = _get_ctx(ctx)
10506 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_away(ctx.ref()), ctx)
10507
10508
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 10494 of file z3py.py.

10494def RNE(ctx=None):
10495 ctx = _get_ctx(ctx)
10496 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_even(ctx.ref()), ctx)
10497
10498
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 4531 of file z3py.py.

4531def RotateLeft(a, b):
4532 """Return an expression representing `a` rotated to the left `b` times.
4533
4534 >>> a, b = BitVecs('a b', 16)
4535 >>> RotateLeft(a, b)
4536 RotateLeft(a, b)
4537 >>> simplify(RotateLeft(a, 0))
4538 a
4539 >>> simplify(RotateLeft(a, 16))
4540 a
4541 """
4542 _check_bv_args(a, b)
4543 a, b = _coerce_exprs(a, b)
4544 return BitVecRef(Z3_mk_ext_rotate_left(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4545
4546
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 4547 of file z3py.py.

4547def RotateRight(a, b):
4548 """Return an expression representing `a` rotated to the right `b` times.
4549
4550 >>> a, b = BitVecs('a b', 16)
4551 >>> RotateRight(a, b)
4552 RotateRight(a, b)
4553 >>> simplify(RotateRight(a, 0))
4554 a
4555 >>> simplify(RotateRight(a, 16))
4556 a
4557 """
4558 _check_bv_args(a, b)
4559 a, b = _coerce_exprs(a, b)
4560 return BitVecRef(Z3_mk_ext_rotate_right(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4561
4562
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 10499 of file z3py.py.

10499def RoundNearestTiesToAway(ctx=None):
10500 ctx = _get_ctx(ctx)
10501 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_away(ctx.ref()), ctx)
10502
10503

◆ RoundNearestTiesToEven()

RoundNearestTiesToEven ( ctx = None)

Definition at line 10489 of file z3py.py.

10489def RoundNearestTiesToEven(ctx=None):
10490 ctx = _get_ctx(ctx)
10491 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_even(ctx.ref()), ctx)
10492
10493

◆ RoundTowardNegative()

RoundTowardNegative ( ctx = None)

Definition at line 10519 of file z3py.py.

10519def RoundTowardNegative(ctx=None):
10520 ctx = _get_ctx(ctx)
10521 return FPRMRef(Z3_mk_fpa_round_toward_negative(ctx.ref()), ctx)
10522
10523
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 10509 of file z3py.py.

10509def RoundTowardPositive(ctx=None):
10510 ctx = _get_ctx(ctx)
10511 return FPRMRef(Z3_mk_fpa_round_toward_positive(ctx.ref()), ctx)
10512
10513
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 10529 of file z3py.py.

10529def RoundTowardZero(ctx=None):
10530 ctx = _get_ctx(ctx)
10531 return FPRMRef(Z3_mk_fpa_round_toward_zero(ctx.ref()), ctx)
10532
10533
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 10524 of file z3py.py.

10524def RTN(ctx=None):
10525 ctx = _get_ctx(ctx)
10526 return FPRMRef(Z3_mk_fpa_round_toward_negative(ctx.ref()), ctx)
10527
10528

◆ RTP()

RTP ( ctx = None)

Definition at line 10514 of file z3py.py.

10514def RTP(ctx=None):
10515 ctx = _get_ctx(ctx)
10516 return FPRMRef(Z3_mk_fpa_round_toward_positive(ctx.ref()), ctx)
10517
10518

◆ RTZ()

RTZ ( ctx = None)

Definition at line 10534 of file z3py.py.

10534def RTZ(ctx=None):
10535 ctx = _get_ctx(ctx)
10536 return FPRMRef(Z3_mk_fpa_round_toward_zero(ctx.ref()), ctx)
10537
10538

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

5048def Select(a, *args):
5049 """Return a Z3 select array expression.
5050
5051 >>> a = Array('a', IntSort(), IntSort())
5052 >>> i = Int('i')
5053 >>> Select(a, i)
5054 a[i]
5055 >>> eq(Select(a, i), a[i])
5056 True
5057 """
5058 args = _get_args(args)
5059 if z3_debug():
5060 _z3_assert(is_array_sort(a), "First argument must be a Z3 array expression")
5061 return a[args]
5062
5063

◆ SeqFoldLeft()

SeqFoldLeft ( f,
a,
s )

Definition at line 12010 of file z3py.py.

12010def SeqFoldLeft(f, a, s):
12011 ctx = _get_ctx2(f, s)
12012 s = _coerce_seq(s, ctx)
12013 a = _py2expr(a)
12014 return _to_expr_ref(Z3_mk_seq_foldl(s.ctx_ref(), f.as_ast(), a.as_ast(), s.as_ast()), ctx)
12015
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 12016 of file z3py.py.

12016def SeqFoldLeftI(f, i, a, s):
12017 ctx = _get_ctx2(f, s)
12018 s = _coerce_seq(s, ctx)
12019 a = _py2expr(a)
12020 i = _py2expr(i)
12021 return _to_expr_ref(Z3_mk_seq_foldli(s.ctx_ref(), f.as_ast(), i.as_ast(), a.as_ast(), s.as_ast()), ctx)
12022
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 11996 of file z3py.py.

11996def SeqMap(f, s):
11997 """Map function 'f' over sequence 's'"""
11998 ctx = _get_ctx2(f, s)
11999 s = _coerce_seq(s, ctx)
12000 return _to_expr_ref(Z3_mk_seq_map(s.ctx_ref(), f.as_ast(), s.as_ast()), ctx)
12001
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 12002 of file z3py.py.

12002def SeqMapI(f, i, s):
12003 """Map function 'f' over sequence 's' at index 'i'"""
12004 ctx = _get_ctx2(f, s)
12005 s = _coerce_seq(s, ctx)
12006 if not is_expr(i):
12007 i = _py2expr(i)
12008 return _to_expr_ref(Z3_mk_seq_mapi(s.ctx_ref(), f.as_ast(), i.as_ast(), s.as_ast()), ctx)
12009
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.

◆ SeqPower()

SeqPower ( s,
n )
Concatenate the sequence 's' with itself 'n' times. It is the empty sequence for n <= 0
>>> p = SeqPower(StringVal("ab"), 2)
>>> simplify(p)
"abab"

Definition at line 11986 of file z3py.py.

11986def SeqPower(s, n):
11987 """Concatenate the sequence 's' with itself 'n' times. It is the empty sequence for n <= 0
11988 >>> p = SeqPower(StringVal("ab"), 2)
11989 >>> simplify(p)
11990 "abab"
11991 """
11992 s = _coerce_seq(s)
11993 n = _py2expr(n, s.ctx)
11994 return SeqRef(Z3_mk_seq_power(s.ctx_ref(), s.as_ast(), n.as_ast()), s.ctx)
11995
Z3_ast Z3_API Z3_mk_seq_power(Z3_context c, Z3_ast s, Z3_ast n)
Create the sequence s concatenated n times with itself. The result is the empty sequence when n is no...

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

11630def SeqSort(s):
11631 """Create a sequence sort over elements provided in the argument
11632 >>> s = SeqSort(IntSort())
11633 >>> s == Unit(IntVal(1)).sort()
11634 True
11635 """
11636 return SeqSortRef(Z3_mk_seq_sort(s.ctx_ref(), s.ast), s.ctx)
11637
11638
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 10150 of file z3py.py.

10150def set_default_fp_sort(ebits, sbits, ctx=None):
10151 global _dflt_fpsort_ebits
10152 global _dflt_fpsort_sbits
10153 _dflt_fpsort_ebits = ebits
10154 _dflt_fpsort_sbits = sbits
10155
10156

◆ set_default_rounding_mode()

set_default_rounding_mode ( rm,
ctx = None )

Definition at line 10137 of file z3py.py.

10137def set_default_rounding_mode(rm, ctx=None):
10138 global _dflt_rounding_mode
10139 if is_fprm_value(rm):
10140 _dflt_rounding_mode = rm.kind()
10141 else:
10142 _z3_assert(_dflt_rounding_mode in _ROUNDING_MODES, "illegal rounding mode")
10143 _dflt_rounding_mode = rm
10144
10145

◆ set_option()

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

Definition at line 328 of file z3py.py.

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

◆ set_param()

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

>>> set_param(precision=10)

Definition at line 298 of file z3py.py.

298def set_param(*args, **kws):
299 """Set Z3 global (or module) parameters.
300
301 >>> set_param(precision=10)
302 """
303 if z3_debug():
304 _z3_assert(len(args) % 2 == 0, "Argument list must have an even number of elements.")
305 new_kws = {}
306 for k in kws:
307 v = kws[k]
308 if not set_pp_option(k, v):
309 new_kws[k] = v
310 for key in new_kws:
311 value = new_kws[key]
312 Z3_global_param_set(str(key).upper(), _to_param_value(value))
313 prev = None
314 for a in args:
315 if prev is None:
316 prev = a
317 else:
318 Z3_global_param_set(str(prev), _to_param_value(a))
319 prev = None
320
321
void Z3_API Z3_global_param_set(Z3_string param_id, Z3_string param_value)
Set a global (or module) parameter. This setting is shared by all Z3 contexts.

Referenced by set_option().

◆ SetAdd()

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

Definition at line 5227 of file z3py.py.

5227def SetAdd(s, e):
5228 """ Add element e to set s
5229 >>> a = Const('a', SetSort(IntSort()))
5230 >>> SetAdd(a, 1)
5231 Store(a, 1, True)
5232 """
5233 ctx = _ctx_from_ast_arg_list([s, e])
5234 e = _py2expr(e, ctx)
5235 if is_finite_set(s):
5236 return FiniteSetSingleton(e) | s
5237 return ArrayRef(Z3_mk_set_add(ctx.ref(), s.as_ast(), e.as_ast()), ctx)
5238
5239
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 5253 of file z3py.py.

5253def SetComplement(s):
5254 """ The complement of set s
5255 >>> a = Const('a', SetSort(IntSort()))
5256 >>> SetComplement(a)
5257 complement(a)
5258 """
5259 ctx = s.ctx
5260 return ArrayRef(Z3_mk_set_complement(ctx.ref(), s.as_ast()), ctx)
5261
5262
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 5240 of file z3py.py.

5240def SetDel(s, e):
5241 """ Remove element e to set s
5242 >>> a = Const('a', SetSort(IntSort()))
5243 >>> SetDel(a, 1)
5244 Store(a, 1, False)
5245 """
5246 ctx = _ctx_from_ast_arg_list([s, e])
5247 e = _py2expr(e, ctx)
5248 if is_finite_set(s):
5249 return s - FiniteSetSingleton(e)
5250 return ArrayRef(Z3_mk_set_del(ctx.ref(), s.as_ast(), e.as_ast()), ctx)
5251
5252
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 5263 of file z3py.py.

5263def SetDifference(a, b):
5264 """ The set difference of a and b
5265 >>> a = Const('a', SetSort(IntSort()))
5266 >>> b = Const('b', SetSort(IntSort()))
5267 >>> SetDifference(a, b)
5268 setminus(a, b)
5269 """
5270 ctx = _ctx_from_ast_arg_list([a, b])
5271 if is_finite_set(a):
5272 return FiniteSetDifference(a, b)
5273 return ArrayRef(Z3_mk_set_difference(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
5274
5275
Z3_ast Z3_API Z3_mk_set_difference(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Take the set difference between two sets.

◆ SetIntersect()

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

Definition at line 5211 of file z3py.py.

5211def SetIntersect(*args):
5212 """ Take the union of sets
5213 >>> a = Const('a', SetSort(IntSort()))
5214 >>> b = Const('b', SetSort(IntSort()))
5215 >>> SetIntersect(a, b)
5216 intersection(a, b)
5217 """
5218 args = _get_args(args)
5219 ctx = _ctx_from_ast_arg_list(args)
5220 if len(args) > 0 and is_finite_set(args[0]):
5221 from functools import reduce
5222 return reduce(FiniteSetIntersect, args)
5223 _args, sz = _to_ast_array(args)
5224 return ArrayRef(Z3_mk_set_intersect(ctx.ref(), sz, _args), ctx)
5225
5226
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 5170 of file z3py.py.

5170def SetSort(s):
5171 """ Create a set sort over element sort s"""
5172 return ArraySort(s, BoolSort())
5173
5174

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

5195def SetUnion(*args):
5196 """ Take the union of sets
5197 >>> a = Const('a', SetSort(IntSort()))
5198 >>> b = Const('b', SetSort(IntSort()))
5199 >>> SetUnion(a, b)
5200 union(a, b)
5201 """
5202 args = _get_args(args)
5203 if len(args) > 0 and is_finite_set(args[0]):
5204 from functools import reduce
5205 return reduce(FiniteSetUnion, args)
5206 ctx = _ctx_from_ast_arg_list(args)
5207 _args, sz = _to_ast_array(args)
5208 return ArrayRef(Z3_mk_set_union(ctx.ref(), sz, _args), ctx)
5209
5210
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 4563 of file z3py.py.

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

8136def SimpleSolver(ctx=None, logFile=None):
8137 """Return a simple general purpose solver with limited amount of preprocessing.
8138
8139 >>> s = SimpleSolver()
8140 >>> x = Int('x')
8141 >>> s.add(x > 0)
8142 >>> s.check()
8143 sat
8144 """
8145 ctx = _get_ctx(ctx)
8146 return Solver(Z3_mk_simple_solver(ctx.ref()), ctx, logFile)
8147
Z3_solver Z3_API Z3_mk_simple_solver(Z3_context c)
Create a new incremental solver.

◆ simplifier_description()

simplifier_description ( name,
ctx = None )
Return the description of the simplifier identified by name.

Definition at line 8944 of file z3py.py.

8944def simplifier_description(name, ctx=None):
8945 """Return the description of the simplifier identified by name."""
8946 return Z3_simplifier_get_descr(_get_ctx(ctx).ref(), name)
8947
8948
Z3_string Z3_API Z3_simplifier_get_descr(Z3_context c, Z3_string name)
Return a string containing a description of the simplifier with the given name.

◆ simplifier_name()

simplifier_name ( i,
ctx = None )
Return the name of the i-th simplifier supported by the given context.

Definition at line 8939 of file z3py.py.

8939def simplifier_name(i, ctx=None):
8940 """Return the name of the i-th simplifier supported by the given context."""
8941 return Z3_get_simplifier_name(_get_ctx(ctx).ref(), i)
8942
8943
Z3_string Z3_API Z3_get_simplifier_name(Z3_context c, unsigned i)
Return the name of the idx simplifier.

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

9594def simplify(a, *arguments, **keywords):
9595 """Simplify the expression `a` using the given options.
9596
9597 This function has many options. Use `help_simplify` to obtain the complete list.
9598
9599 >>> x = Int('x')
9600 >>> y = Int('y')
9601 >>> simplify(x + 1 + y + x + 1)
9602 2 + 2*x + y
9603 >>> simplify((x + 1)*(y + 1), som=True)
9604 1 + x + y + x*y
9605 >>> simplify(Distinct(x, y, 1), blast_distinct=True)
9606 And(Not(x == y), Not(x == 1), Not(y == 1))
9607 >>> simplify(And(x == 0, y == 1), elim_and=True)
9608 Not(Or(Not(x == 0), Not(y == 1)))
9609 """
9610 if z3_debug():
9611 _z3_assert(is_expr(a), "Z3 expression expected")
9612 if len(arguments) > 0 or len(keywords) > 0:
9613 p = args2params(arguments, keywords, a.ctx)
9614 return _to_expr_ref(Z3_simplify_ex(a.ctx_ref(), a.as_ast(), p.params), a.ctx)
9615 else:
9616 return _to_expr_ref(Z3_simplify(a.ctx_ref(), a.as_ast()), a.ctx)
9617
9618
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 9624 of file z3py.py.

9624def simplify_param_descrs():
9625 """Return the set of parameter descriptions for Z3 `simplify` procedure."""
9626 return ParamDescrsRef(Z3_simplify_get_param_descrs(main_ctx().ref()), main_ctx())
9627
9628
Z3_param_descrs Z3_API Z3_simplify_get_param_descrs(Z3_context c)
Return the parameter description set for the simplify procedure.

◆ Singleton()

Singleton ( elem)
Create a singleton finite set containing elem.
>>> Singleton(IntVal(1))
set.singleton(1)

Definition at line 5409 of file z3py.py.

5409def Singleton(elem):
5410 """Create a singleton finite set containing elem.
5411 >>> Singleton(IntVal(1))
5412 set.singleton(1)
5413 """
5414 ctx = elem.ctx
5415 return FiniteSetRef(Z3_mk_finite_set_singleton(ctx.ref(), elem.as_ast()), ctx)
5416
5417
Z3_ast Z3_API Z3_mk_finite_set_singleton(Z3_context c, Z3_ast elem)
Create a singleton finite set.

Referenced by FiniteSetSortRef.cast().

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

9856def solve(*args, **keywords):
9857 """Solve the constraints `*args`.
9858
9859 This is a simple function for creating demonstrations. It creates a solver,
9860 configure it using the options in `keywords`, adds the constraints
9861 in `args`, and invokes check.
9862
9863 >>> a = Int('a')
9864 >>> solve(a > 0, a < 2)
9865 [a = 1]
9866 """
9867 show = keywords.pop("show", False)
9868 s = Solver()
9869 s.set(**keywords)
9870 s.add(*args)
9871 if show:
9872 print(s)
9873 r = s.check()
9874 if r == unsat:
9875 print("no solution")
9876 elif r == unknown:
9877 print("failed to solve")
9878 try:
9879 print(s.model())
9880 except Z3Exception:
9881 return
9882 else:
9883 print(s.model())
9884
9885

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

9886def solve_using(s, *args, **keywords):
9887 """Solve the constraints `*args` using solver `s`.
9888
9889 This is a simple function for creating demonstrations. It is similar to `solve`,
9890 but it uses the given solver `s`.
9891 It configures solver `s` using the options in `keywords`, adds the constraints
9892 in `args`, and invokes check.
9893 """
9894 show = keywords.pop("show", False)
9895 if z3_debug():
9896 _z3_assert(isinstance(s, Solver), "Solver object expected")
9897 s.set(**keywords)
9898 s.add(*args)
9899 if show:
9900 print("Problem:")
9901 print(s)
9902 r = s.check()
9903 if r == unsat:
9904 print("no solution")
9905 elif r == unknown:
9906 print("failed to solve")
9907 try:
9908 print(s.model())
9909 except Z3Exception:
9910 return
9911 else:
9912 if show:
9913 print("Solution:")
9914 print(s.model())
9915
9916

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

8115def SolverFor(logic, ctx=None, logFile=None):
8116 """Create a solver customized for the given logic.
8117
8118 The parameter `logic` is a string. It should be contains
8119 the name of a SMT-LIB logic.
8120 See http://www.smtlib.org/ for the name of all available logics.
8121
8122 >>> s = SolverFor("QF_LIA")
8123 >>> x = Int('x')
8124 >>> s.add(x > 0)
8125 >>> s.add(x < 2)
8126 >>> s.check()
8127 sat
8128 >>> s.model()
8129 [x = 1]
8130 """
8131 ctx = _get_ctx(ctx)
8132 logic = to_symbol(logic)
8133 return Solver(Z3_mk_solver_for_logic(ctx.ref(), logic), ctx, logFile)
8134
8135
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 3583 of file z3py.py.

3583def Sqrt(a, ctx=None):
3584 """ Return a Z3 expression which represents the square root of a.
3585
3586 >>> x = Real('x')
3587 >>> Sqrt(x)
3588 x**(1/2)
3589 """
3590 if not is_expr(a):
3591 ctx = _get_ctx(ctx)
3592 a = RealVal(a, ctx)
3593 return a ** "1/2"
3594
3595

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

4478def SRem(a, b):
4479 """Create the Z3 expression signed remainder.
4480
4481 Use the operator % for signed modulus, and URem() for unsigned remainder.
4482
4483 >>> x = BitVec('x', 32)
4484 >>> y = BitVec('y', 32)
4485 >>> SRem(x, y)
4486 SRem(x, y)
4487 >>> SRem(x, y).sort()
4488 BitVec(32)
4489 >>> (x % y).sexpr()
4490 '(bvsmod x y)'
4491 >>> SRem(x, y).sexpr()
4492 '(bvsrem x y)'
4493 """
4494 _check_bv_args(a, b)
4495 a, b = _coerce_exprs(a, b)
4496 return BitVecRef(Z3_mk_bvsrem(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4497
4498
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 12200 of file z3py.py.

12200def Star(re):
12201 """Create the regular expression accepting zero or more repetitions of argument.
12202 >>> re = Star(Re("a"))
12203 >>> print(simplify(InRe("aa", re)))
12204 True
12205 >>> print(simplify(InRe("ab", re)))
12206 False
12207 >>> print(simplify(InRe("", re)))
12208 True
12209 """
12210 if z3_debug():
12211 _z3_assert(is_expr(re), "expression expected")
12212 return ReRef(Z3_mk_re_star(re.ctx_ref(), re.as_ast()), re.ctx)
12213
12214
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 5031 of file z3py.py.

5031def Store(a, *args):
5032 """Return a Z3 store array expression.
5033
5034 >>> a = Array('a', IntSort(), IntSort())
5035 >>> i, v = Ints('i v')
5036 >>> s = Store(a, i, v)
5037 >>> s.sort()
5038 Array(Int, Int)
5039 >>> prove(s[i] == v)
5040 proved
5041 >>> j = Int('j')
5042 >>> prove(Implies(i != j, s[j] == a[j]))
5043 proved
5044 """
5045 return Update(a, args)
5046
5047

Referenced by ModelRef.get_interp().

◆ StrFromCode()

StrFromCode ( c)
Convert code to a string

Definition at line 12052 of file z3py.py.

12052def StrFromCode(c):
12053 """Convert code to a string"""
12054 if not is_expr(c):
12055 c = _py2expr(c)
12056 return SeqRef(Z3_mk_string_from_code(c.ctx_ref(), c.as_ast()), c.ctx)
12057
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 11799 of file z3py.py.

11799def String(name, ctx=None):
11800 """Return a string constant named `name`. If `ctx=None`, then the global context is used.
11801
11802 >>> x = String('x')
11803 """
11804 ctx = _get_ctx(ctx)
11805 return SeqRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), StringSort(ctx).ast), ctx)
11806
11807

◆ Strings()

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

Definition at line 11808 of file z3py.py.

11808def Strings(names, ctx=None):
11809 """Return a tuple of String constants. """
11810 ctx = _get_ctx(ctx)
11811 if isinstance(names, str):
11812 names = names.split(" ")
11813 return [String(name, ctx) for name in names]
11814
11815

◆ StringSort()

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

Definition at line 11611 of file z3py.py.

11611def StringSort(ctx=None):
11612 """Create a string sort
11613 >>> s = StringSort()
11614 >>> print(s)
11615 String
11616 """
11617 ctx = _get_ctx(ctx)
11618 return SeqSortRef(Z3_mk_string_sort(ctx.ref()), ctx)
11619

◆ StringVal()

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

Definition at line 11792 of file z3py.py.

11792def StringVal(s, ctx=None):
11793 """create a string expression"""
11794 s = "".join(str(ch) if 32 <= ord(ch) and ord(ch) < 127 else "\\u{%x}" % (ord(ch)) for ch in s)
11795 ctx = _get_ctx(ctx)
11796 return SeqRef(Z3_mk_string(ctx.ref(), s), ctx)
11797
11798
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 12046 of file z3py.py.

12046def StrToCode(s):
12047 """Convert a unit length string to integer code"""
12048 if not is_expr(s):
12049 s = _py2expr(s)
12050 return ArithRef(Z3_mk_string_to_code(s.ctx_ref(), s.as_ast()), s.ctx)
12051
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 12023 of file z3py.py.

12023def StrToInt(s):
12024 """Convert string expression to integer
12025 >>> a = StrToInt("1")
12026 >>> simplify(1 == a)
12027 True
12028 >>> b = StrToInt("2")
12029 >>> simplify(1 == b)
12030 False
12031 >>> c = StrToInt(IntToStr(2))
12032 >>> simplify(1 == c)
12033 False
12034 """
12035 s = _coerce_seq(s)
12036 return ArithRef(Z3_mk_str_to_int(s.ctx_ref(), s.as_ast()), s.ctx)
12037
12038
Z3_ast Z3_API Z3_mk_str_to_int(Z3_context c, Z3_ast s)
Convert string to integer.

◆ SubSeq()

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

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

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

Definition at line 11830 of file z3py.py.

11830def SubSeq(s, offset, length):
11831 """Extract substring or subsequence starting at offset.
11832
11833 This is a convenience function that redirects to Extract(s, offset, length).
11834
11835 >>> s = StringVal("hello world")
11836 >>> SubSeq(s, 0, 5) # Extract "hello"
11837 str.substr("hello world", 0, 5)
11838 >>> simplify(SubSeq(StringVal("testing"), 2, 4))
11839 "stin"
11840 """
11841 return Extract(s, offset, length)
11842
11843

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

9629def substitute(t, *m):
9630 """Apply substitution m on t, m is a list of pairs of the form (from, to).
9631 Every occurrence in t of from is replaced with to.
9632
9633 >>> x = Int('x')
9634 >>> y = Int('y')
9635 >>> substitute(x + 1, (x, y + 1))
9636 y + 1 + 1
9637 >>> f = Function('f', IntSort(), IntSort())
9638 >>> substitute(f(x) + f(y), (f(x), IntVal(1)), (f(y), IntVal(1)))
9639 1 + 1
9640 """
9641 if isinstance(m, tuple):
9642 m1 = _get_args(m)
9643 if isinstance(m1, list) and all(isinstance(p, tuple) for p in m1):
9644 m = m1
9645 if z3_debug():
9646 _z3_assert(is_expr(t), "Z3 expression expected")
9647 _z3_assert(
9648 all([isinstance(p, tuple) and is_expr(p[0]) and is_expr(p[1]) for p in m]),
9649 "Z3 invalid substitution, expression pairs expected.")
9650 _z3_assert(
9651 all([p[0].sort().eq(p[1].sort()) for p in m]),
9652 'Z3 invalid substitution, mismatching "from" and "to" sorts.')
9653 num = len(m)
9654 _from = (Ast * num)()
9655 _to = (Ast * num)()
9656 for i in range(num):
9657 _from[i] = m[i][0].as_ast()
9658 _to[i] = m[i][1].as_ast()
9659 return _to_expr_ref(Z3_substitute(t.ctx.ref(), t.as_ast(), num, _from, _to), t.ctx)
9660
9661
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 9682 of file z3py.py.

9682def substitute_funs(t, *m):
9683 """Apply substitution m on t, m is a list of pairs of a function and expression (from, to)
9684 Every occurrence in to of the function from is replaced with the expression to.
9685 The expression to can have free variables, that refer to the arguments of from.
9686 For examples, see
9687 """
9688 if isinstance(m, tuple):
9689 m1 = _get_args(m)
9690 if isinstance(m1, list) and all(isinstance(p, tuple) for p in m1):
9691 m = m1
9692 if z3_debug():
9693 _z3_assert(is_expr(t), "Z3 expression expected")
9694 _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.")
9695 num = len(m)
9696 _from = (FuncDecl * num)()
9697 _to = (Ast * num)()
9698 for i in range(num):
9699 _from[i] = m[i][0].as_func_decl()
9700 _to[i] = m[i][1].as_ast()
9701 return _to_expr_ref(Z3_substitute_funs(t.ctx.ref(), t.as_ast(), num, _from, _to), t.ctx)
9702
9703
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 9662 of file z3py.py.

9662def substitute_vars(t, *m):
9663 """Substitute the free variables in t with the expression in m.
9664
9665 >>> v0 = Var(0, IntSort())
9666 >>> v1 = Var(1, IntSort())
9667 >>> x = Int('x')
9668 >>> f = Function('f', IntSort(), IntSort(), IntSort())
9669 >>> # replace v0 with x+1 and v1 with x
9670 >>> substitute_vars(f(v0, v1), x + 1, x)
9671 f(x + 1, x)
9672 """
9673 if z3_debug():
9674 _z3_assert(is_expr(t), "Z3 expression expected")
9675 _z3_assert(all([is_expr(n) for n in m]), "Z3 invalid substitution, list of expressions expected.")
9676 num = len(m)
9677 _to = (Ast * num)()
9678 for i in range(num):
9679 _to[i] = m[i].as_ast()
9680 return _to_expr_ref(Z3_substitute_vars(t.ctx.ref(), t.as_ast(), num, _to), t.ctx)
9681
Z3_ast Z3_API Z3_substitute_vars(Z3_context c, Z3_ast a, unsigned num_exprs, Z3_ast const to[])
Substitute the variables in a with the expressions in to. For every i smaller than num_exprs,...

◆ SubString()

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

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

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

Definition at line 11816 of file z3py.py.

11816def SubString(s, offset, length):
11817 """Extract substring or subsequence starting at offset.
11818
11819 This is a convenience function that redirects to Extract(s, offset, length).
11820
11821 >>> s = StringVal("hello world")
11822 >>> SubString(s, 6, 5) # Extract "world"
11823 str.substr("hello world", 6, 5)
11824 >>> simplify(SubString(StringVal("hello"), 1, 3))
11825 "ell"
11826 """
11827 return Extract(s, offset, length)
11828
11829

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

11899def SuffixOf(a, b):
11900 """Check if 'a' is a suffix of 'b'
11901 >>> s1 = SuffixOf("ab", "abc")
11902 >>> simplify(s1)
11903 False
11904 >>> s2 = SuffixOf("bc", "abc")
11905 >>> simplify(s2)
11906 True
11907 """
11908 ctx = _get_ctx2(a, b)
11909 a = _coerce_seq(a, ctx)
11910 b = _coerce_seq(b, ctx)
11911 return BoolRef(Z3_mk_seq_suffix(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
11912
11913
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 9704 of file z3py.py.

9704def Sum(*args):
9705 """Create the sum of the Z3 expressions.
9706
9707 >>> a, b, c = Ints('a b c')
9708 >>> Sum(a, b, c)
9709 a + b + c
9710 >>> Sum([a, b, c])
9711 a + b + c
9712 >>> A = IntVector('a', 5)
9713 >>> Sum(A)
9714 a__0 + a__1 + a__2 + a__3 + a__4
9715 """
9716 args = _get_args(args)
9717 if len(args) == 0:
9718 return 0
9719 ctx = _ctx_from_ast_arg_list(args)
9720 if ctx is None:
9721 return _reduce(lambda a, b: a + b, args, 0)
9722 args = _coerce_expr_list(args, ctx)
9723 if is_bv(args[0]) or isinstance(args[0], FiniteFieldRef):
9724 return _reduce(lambda a, b: a + b, args, 0)
9725 else:
9726 _args, sz = _to_ast_array(args)
9727 return ArithRef(Z3_mk_add(ctx.ref(), sz, _args), ctx)
9728
9729
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 9283 of file z3py.py.

9283def tactic_description(name, ctx=None):
9284 """Return a short description for the tactic named `name`.
9285
9286 >>> d = tactic_description('simplify')
9287 """
9288 ctx = _get_ctx(ctx)
9289 return Z3_tactic_get_descr(ctx.ref(), name)
9290
9291
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 9272 of file z3py.py.

9272def tactics(ctx=None):
9273 """Return a list of all available tactics in Z3.
9274
9275 >>> l = tactics()
9276 >>> l.count('simplify') == 1
9277 True
9278 """
9279 ctx = _get_ctx(ctx)
9280 return [Z3_get_tactic_name(ctx.ref(), i) for i in range(Z3_get_num_tactics(ctx.ref()))]
9281
9282
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 9140 of file z3py.py.

9140def Then(*ts, **ks):
9141 """Return a tactic that applies the tactics in `*ts` in sequence. Shorthand for AndThen(*ts, **ks).
9142
9143 >>> x, y = Ints('x y')
9144 >>> t = Then(Tactic('simplify'), Tactic('solve-eqs'))
9145 >>> t(And(x == 0, y > x + 1))
9146 [[Not(y <= 1)]]
9147 >>> t(And(x == 0, y > x + 1)).as_expr()
9148 Not(y <= 1)
9149 """
9150 return AndThen(*ts, **ks)
9151
9152

◆ to_Ast()

to_Ast ( ptr)

Definition at line 12284 of file z3py.py.

12284def to_Ast(ptr,):
12285 ast = Ast(ptr)
12286 super(ctypes.c_void_p, ast).__init__(ptr)
12287 return ast
12288

◆ to_AstVectorObj()

to_AstVectorObj ( ptr)

Definition at line 12294 of file z3py.py.

12294def to_AstVectorObj(ptr,):
12295 v = AstVectorObj(ptr)
12296 super(ctypes.c_void_p, v).__init__(ptr)
12297 return v
12298
12299# NB. my-hacky-class only works for a single instance of OnClause
12300# it should be replaced with a proper correlation between OnClause
12301# and object references that can be passed over the FFI.
12302# for UserPropagator we use a global dictionary, which isn't great code.
12303

◆ to_ContextObj()

to_ContextObj ( ptr)

Definition at line 12289 of file z3py.py.

12289def to_ContextObj(ptr,):
12290 ctx = ContextObj(ptr)
12291 super(ctypes.c_void_p, ctx).__init__(ptr)
12292 return ctx
12293

◆ to_symbol()

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

Definition at line 132 of file z3py.py.

132def to_symbol(s, ctx = None):
133 """Convert an integer or string into a Z3 symbol."""
134 if _is_int(s):
135 return Z3_mk_int_symbol(_get_ctx(ctx).ref(), s)
136 else:
137 return Z3_mk_string_symbol(_get_ctx(ctx).ref(), s)
138
139
Z3_symbol Z3_API Z3_mk_string_symbol(Z3_context c, Z3_string s)
Create a Z3 symbol using a C string.
Z3_symbol Z3_API Z3_mk_int_symbol(Z3_context c, int i)
Create a Z3 symbol using an integer.

Referenced by _mk_quantifier(), Array(), BitVec(), Bool(), Const(), CreateDatatypes(), CreatePolymorphicDatatype(), 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 3548 of file z3py.py.

3548def ToInt(a):
3549 """ Return the Z3 expression ToInt(a).
3550
3551 >>> x = Real('x')
3552 >>> x.sort()
3553 Real
3554 >>> n = ToInt(x)
3555 >>> n
3556 ToInt(x)
3557 >>> n.sort()
3558 Int
3559 """
3560 if z3_debug():
3561 _z3_assert(a.is_real(), "Z3 real expression expected.")
3562 ctx = a.ctx
3563 return ArithRef(Z3_mk_real2int(ctx.ref(), a.as_ast()), ctx)
3564
3565
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 3528 of file z3py.py.

3528def ToReal(a):
3529 """ Return the Z3 expression ToReal(a).
3530
3531 >>> x = Int('x')
3532 >>> x.sort()
3533 Int
3534 >>> n = ToReal(x)
3535 >>> n
3536 ToReal(x)
3537 >>> n.sort()
3538 Real
3539 """
3540 ctx = a.ctx
3541 if isinstance(a, BoolRef):
3542 return If(a, RealVal(1, ctx), RealVal(0, ctx))
3543 if z3_debug():
3544 _z3_assert(a.is_int(), "Z3 integer expression expected.")
3545 return ArithRef(Z3_mk_int2real(ctx.ref(), a.as_ast()), ctx)
3546
3547
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 12277 of file z3py.py.

12277def TransitiveClosure(f):
12278 """Given a binary relation R, such that the two arguments have the same sort
12279 create the transitive closure relation R+.
12280 The transitive closure R+ is a new relation.
12281 """
12282 return FuncDeclRef(Z3_mk_transitive_closure(f.ctx_ref(), f.ast), f.ctx)
12283
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 12269 of file z3py.py.

12269def TreeOrder(a, index):
12270 return FuncDeclRef(Z3_mk_tree_order(a.ctx_ref(), a.ast, index), a.ctx)
12271
12272
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 9263 of file z3py.py.

9263def TryFor(t, ms, ctx=None):
9264 """Return a tactic that applies `t` to a given goal for `ms` milliseconds.
9265
9266 If `t` does not terminate in `ms` milliseconds, then it fails.
9267 """
9268 t = _to_tactic(t, ctx)
9269 return Tactic(Z3_tactic_try_for(t.ctx.ref(), t.tactic, ms), t.ctx)
9270
9271
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 5981 of file z3py.py.

5981def TupleSort(name, sorts, ctx=None):
5982 """Create a named tuple sort base on a set of underlying sorts
5983 Example:
5984 >>> pair, mk_pair, (first, second) = TupleSort("pair", [IntSort(), StringSort()])
5985 """
5986 tuple = Datatype(name, ctx)
5987 projects = [("project%d" % i, sorts[i]) for i in range(len(sorts))]
5988 tuple.declare(name, *projects)
5989 tuple = tuple.create()
5990 return tuple, tuple.constructor(0), [tuple.accessor(0, i) for i in range(len(sorts))]
5991
5992

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

4436def UDiv(a, b):
4437 """Create the Z3 expression (unsigned) division `self / other`.
4438
4439 Use the operator / for signed division.
4440
4441 >>> x = BitVec('x', 32)
4442 >>> y = BitVec('y', 32)
4443 >>> UDiv(x, y)
4444 UDiv(x, y)
4445 >>> UDiv(x, y).sort()
4446 BitVec(32)
4447 >>> (x / y).sexpr()
4448 '(bvsdiv x y)'
4449 >>> UDiv(x, y).sexpr()
4450 '(bvudiv x y)'
4451 """
4452 _check_bv_args(a, b)
4453 a, b = _coerce_exprs(a, b)
4454 return BitVecRef(Z3_mk_bvudiv(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4455
4456
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 4400 of file z3py.py.

4400def UGE(a, b):
4401 """Create the Z3 expression (unsigned) `other >= self`.
4402
4403 Use the operator >= for signed greater than or equal to.
4404
4405 >>> x, y = BitVecs('x y', 32)
4406 >>> UGE(x, y)
4407 UGE(x, y)
4408 >>> (x >= y).sexpr()
4409 '(bvsge x y)'
4410 >>> UGE(x, y).sexpr()
4411 '(bvuge x y)'
4412 """
4413 _check_bv_args(a, b)
4414 a, b = _coerce_exprs(a, b)
4415 return BoolRef(Z3_mk_bvuge(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4416
4417
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 4418 of file z3py.py.

4418def UGT(a, b):
4419 """Create the Z3 expression (unsigned) `other > self`.
4420
4421 Use the operator > for signed greater than.
4422
4423 >>> x, y = BitVecs('x y', 32)
4424 >>> UGT(x, y)
4425 UGT(x, y)
4426 >>> (x > y).sexpr()
4427 '(bvsgt x y)'
4428 >>> UGT(x, y).sexpr()
4429 '(bvugt x y)'
4430 """
4431 _check_bv_args(a, b)
4432 a, b = _coerce_exprs(a, b)
4433 return BoolRef(Z3_mk_bvugt(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4434
4435
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 4364 of file z3py.py.

4364def ULE(a, b):
4365 """Create the Z3 expression (unsigned) `other <= self`.
4366
4367 Use the operator <= for signed less than or equal to.
4368
4369 >>> x, y = BitVecs('x y', 32)
4370 >>> ULE(x, y)
4371 ULE(x, y)
4372 >>> (x <= y).sexpr()
4373 '(bvsle x y)'
4374 >>> ULE(x, y).sexpr()
4375 '(bvule x y)'
4376 """
4377 _check_bv_args(a, b)
4378 a, b = _coerce_exprs(a, b)
4379 return BoolRef(Z3_mk_bvule(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4380
4381
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 4382 of file z3py.py.

4382def ULT(a, b):
4383 """Create the Z3 expression (unsigned) `other < self`.
4384
4385 Use the operator < for signed less than.
4386
4387 >>> x, y = BitVecs('x y', 32)
4388 >>> ULT(x, y)
4389 ULT(x, y)
4390 >>> (x < y).sexpr()
4391 '(bvslt x y)'
4392 >>> ULT(x, y).sexpr()
4393 '(bvult x y)'
4394 """
4395 _check_bv_args(a, b)
4396 a, b = _coerce_exprs(a, b)
4397 return BoolRef(Z3_mk_bvult(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4398
4399
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 12111 of file z3py.py.

12111def Union(*args):
12112 """Create union of regular expressions.
12113 >>> re = Union(Re("a"), Re("b"), Re("c"))
12114 >>> print (simplify(InRe("d", re)))
12115 False
12116 """
12117 args = _get_args(args)
12118 sz = len(args)
12119 if z3_debug():
12120 _z3_assert(sz > 0, "At least one argument expected.")
12121 arg0 = args[0]
12122 if is_finite_set(arg0):
12123 for a in args[1:]:
12124 if not is_finite_set(a):
12125 raise Z3Exception("All arguments must be regular expressions or finite sets.")
12126 arg0 = arg0 | a
12127 return arg0
12128 if z3_debug():
12129 _z3_assert(all([is_re(a) for a in args]), "All arguments must be regular expressions.")
12130 if sz == 1:
12131 return args[0]
12132 ctx = args[0].ctx
12133 v = (Ast * sz)()
12134 for i in range(sz):
12135 v[i] = args[i].as_ast()
12136 return ReRef(Z3_mk_re_union(ctx.ref(), sz, v), ctx)
12137
12138
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 11879 of file z3py.py.

11879def Unit(a):
11880 """Create a singleton sequence"""
11881 return SeqRef(Z3_mk_seq_unit(a.ctx_ref(), a.as_ast()), a.ctx)
11882
11883
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 4988 of file z3py.py.

4988def Update(a, *args):
4989 """Return a Z3 store array expression.
4990
4991 >>> a = Array('a', IntSort(), IntSort())
4992 >>> i, v = Ints('i v')
4993 >>> s = Update(a, i, v)
4994 >>> s.sort()
4995 Array(Int, Int)
4996 >>> prove(s[i] == v)
4997 proved
4998 >>> j = Int('j')
4999 >>> prove(Implies(i != j, s[j] == a[j]))
5000 proved
5001 """
5002 if z3_debug():
5003 _z3_assert(is_array_sort(a), "First argument must be a Z3 array expression")
5004 args = _get_args(args)
5005 ctx = a.ctx
5006 if len(args) <= 1:
5007 raise Z3Exception("array update requires index and value arguments")
5008 if len(args) == 2:
5009 i = args[0]
5010 v = args[1]
5011 i = a.sort().domain().cast(i)
5012 v = a.sort().range().cast(v)
5013 return _to_expr_ref(Z3_mk_store(ctx.ref(), a.as_ast(), i.as_ast(), v.as_ast()), ctx)
5014 v = a.sort().range().cast(args[-1])
5015 idxs = [a.sort().domain_n(i).cast(args[i]) for i in range(len(args)-1)]
5016 _args, sz = _to_ast_array(idxs)
5017 return _to_expr_ref(Z3_mk_store_n(ctx.ref(), a.as_ast(), sz, _args, v.as_ast()), ctx)
5018
5019
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 4457 of file z3py.py.

4457def URem(a, b):
4458 """Create the Z3 expression (unsigned) remainder `self % other`.
4459
4460 Use the operator % for signed modulus, and SRem() for signed remainder.
4461
4462 >>> x = BitVec('x', 32)
4463 >>> y = BitVec('y', 32)
4464 >>> URem(x, y)
4465 URem(x, y)
4466 >>> URem(x, y).sort()
4467 BitVec(32)
4468 >>> (x % y).sexpr()
4469 '(bvsmod x y)'
4470 >>> URem(x, y).sexpr()
4471 '(bvurem x y)'
4472 """
4473 _check_bv_args(a, b)
4474 a, b = _coerce_exprs(a, b)
4475 return BitVecRef(Z3_mk_bvurem(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4476
4477
Z3_ast Z3_API Z3_mk_bvurem(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned remainder.

◆ user_prop_binding()

user_prop_binding ( ctx,
cb,
q_ref,
inst_ref )

Definition at line 12447 of file z3py.py.

12447def user_prop_binding(ctx, cb, q_ref, inst_ref):
12448 prop = _prop_closures.get(ctx)
12449 old_cb = prop.cb
12450 prop.cb = cb
12451 q = _to_expr_ref(to_Ast(q_ref), prop.ctx())
12452 inst = _to_expr_ref(to_Ast(inst_ref), prop.ctx())
12453 r = prop.binding(q, inst)
12454 prop.cb = old_cb
12455 return r
12456
12457

◆ user_prop_created()

user_prop_created ( ctx,
cb,
id )

Definition at line 12405 of file z3py.py.

12405def user_prop_created(ctx, cb, id):
12406 prop = _prop_closures.get(ctx)
12407 old_cb = prop.cb
12408 prop.cb = cb
12409 id = _to_expr_ref(to_Ast(id), prop.ctx())
12410 prop.created(id)
12411 prop.cb = old_cb
12412
12413

◆ user_prop_decide()

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

Definition at line 12439 of file z3py.py.

12439def user_prop_decide(ctx, cb, t_ref, idx, phase):
12440 prop = _prop_closures.get(ctx)
12441 old_cb = prop.cb
12442 prop.cb = cb
12443 t = _to_expr_ref(to_Ast(t_ref), prop.ctx())
12444 prop.decide(t, idx, phase)
12445 prop.cb = old_cb
12446

◆ user_prop_diseq()

user_prop_diseq ( ctx,
cb,
x,
y )

Definition at line 12430 of file z3py.py.

12430def user_prop_diseq(ctx, cb, x, y):
12431 prop = _prop_closures.get(ctx)
12432 old_cb = prop.cb
12433 prop.cb = cb
12434 x = _to_expr_ref(to_Ast(x), prop.ctx())
12435 y = _to_expr_ref(to_Ast(y), prop.ctx())
12436 prop.diseq(x, y)
12437 prop.cb = old_cb
12438

◆ user_prop_eq()

user_prop_eq ( ctx,
cb,
x,
y )

Definition at line 12421 of file z3py.py.

12421def user_prop_eq(ctx, cb, x, y):
12422 prop = _prop_closures.get(ctx)
12423 old_cb = prop.cb
12424 prop.cb = cb
12425 x = _to_expr_ref(to_Ast(x), prop.ctx())
12426 y = _to_expr_ref(to_Ast(y), prop.ctx())
12427 prop.eq(x, y)
12428 prop.cb = old_cb
12429

◆ user_prop_final()

user_prop_final ( ctx,
cb )

Definition at line 12414 of file z3py.py.

12414def user_prop_final(ctx, cb):
12415 prop = _prop_closures.get(ctx)
12416 old_cb = prop.cb
12417 prop.cb = cb
12418 prop.final()
12419 prop.cb = old_cb
12420

◆ user_prop_fixed()

user_prop_fixed ( ctx,
cb,
id,
value )

Definition at line 12396 of file z3py.py.

12396def user_prop_fixed(ctx, cb, id, value):
12397 prop = _prop_closures.get(ctx)
12398 old_cb = prop.cb
12399 prop.cb = cb
12400 id = _to_expr_ref(to_Ast(id), prop.ctx())
12401 value = _to_expr_ref(to_Ast(value), prop.ctx())
12402 prop.fixed(id, value)
12403 prop.cb = old_cb
12404

◆ user_prop_fresh()

user_prop_fresh ( ctx,
_new_ctx )

Definition at line 12382 of file z3py.py.

12382def user_prop_fresh(ctx, _new_ctx):
12383 _prop_closures.set_threaded()
12384 prop = _prop_closures.get(ctx)
12385 nctx = Context()
12386 Z3_del_context(nctx.ctx)
12387 new_ctx = to_ContextObj(_new_ctx)
12388 nctx.ctx = new_ctx
12389 nctx.eh = Z3_set_error_handler(new_ctx, z3_error_handler)
12390 nctx.owner = False
12391 new_prop = prop.fresh(nctx)
12392 _prop_closures.set(new_prop.id, new_prop)
12393 return new_prop.id
12394
12395
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 12376 of file z3py.py.

12376def user_prop_pop(ctx, cb, num_scopes):
12377 prop = _prop_closures.get(ctx)
12378 prop.cb = cb
12379 prop.pop(num_scopes)
12380
12381

◆ user_prop_push()

user_prop_push ( ctx,
cb )

Definition at line 12370 of file z3py.py.

12370def user_prop_push(ctx, cb):
12371 prop = _prop_closures.get(ctx)
12372 prop.cb = cb
12373 prop.push()
12374
12375

◆ Var()

ExprRef Var ( int idx,
SortRef s )
Create a Z3 free variable. Free variables are used to create quantified formulas.
A free variable with index n is bound when it occurs within the scope of n+1 quantified
declarations.

>>> Var(0, IntSort())
Var(0)
>>> eq(Var(0, IntSort()), Var(0, BoolSort()))
False

Definition at line 1585 of file z3py.py.

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

9557def When(p, t, ctx=None):
9558 """Return a tactic that applies tactic `t` only if probe `p` evaluates to true.
9559 Otherwise, it returns the input goal unmodified.
9560
9561 >>> t = When(Probe('size') > 2, Tactic('simplify'))
9562 >>> x, y = Ints('x y')
9563 >>> g = Goal()
9564 >>> g.add(x > 0)
9565 >>> g.add(y > 0)
9566 >>> t(g)
9567 [[x > 0, y > 0]]
9568 >>> g.add(x == y + 1)
9569 >>> t(g)
9570 [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
9571 """
9572 p = _to_probe(p, ctx)
9573 t = _to_tactic(t, ctx)
9574 return Tactic(Z3_tactic_when(t.ctx.ref(), p.probe, t.tactic), t.ctx)
9575
9576
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 9214 of file z3py.py.

9214def With(t, *args, **keys):
9215 """Return a tactic that applies tactic `t` using the given configuration options.
9216
9217 >>> x, y = Ints('x y')
9218 >>> t = With(Tactic('simplify'), som=True)
9219 >>> t((x + 1)*(y + 2) == 0)
9220 [[2*x + y + x*y == -2]]
9221 """
9222 ctx = keys.pop("ctx", None)
9223 t = _to_tactic(t, ctx)
9224 p = args2params(args, keys, t.ctx)
9225 return Tactic(Z3_tactic_using_params(t.ctx.ref(), t.tactic, p.params), t.ctx)
9226
9227
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 9228 of file z3py.py.

9228def WithParams(t, p):
9229 """Return a tactic that applies tactic `t` using the given configuration options.
9230
9231 >>> x, y = Ints('x y')
9232 >>> p = ParamsRef()
9233 >>> p.set("som", True)
9234 >>> t = WithParams(Tactic('simplify'), p)
9235 >>> t((x + 1)*(y + 2) == 0)
9236 [[2*x + y + x*y == -2]]
9237 """
9238 t = _to_tactic(t, None)
9239 return Tactic(Z3_tactic_using_params(t.ctx.ref(), t.tactic, p.params), t.ctx)
9240
9241

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

1942def Xor(a, b, ctx=None):
1943 """Create a Z3 Xor expression.
1944
1945 >>> p, q = Bools('p q')
1946 >>> Xor(p, q)
1947 Xor(p, q)
1948 >>> simplify(Xor(p, q))
1949 Not(p == q)
1950 """
1951 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1952 s = BoolSort(ctx)
1953 a = s.cast(a)
1954 b = s.cast(b)
1955 return BoolRef(Z3_mk_xor(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
1956
1957
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 184 of file z3py.py.

184def z3_error_handler(c, e):
185 # Do nothing error handler, just avoid exit(0)
186 # The wrappers in z3core.py will raise a Z3Exception if an error is detected
187 return
188
189

◆ ZeroExt()

ZeroExt ( n,
a )
Return a bit-vector expression with `n` extra zero-bits.

>>> x = BitVec('x', 16)
>>> n = ZeroExt(8, x)
>>> n.size()
24
>>> n
ZeroExt(8, x)
>>> n.sort()
BitVec(24)
>>> v0 = BitVecVal(2, 2)
>>> v0
2
>>> v0.size()
2
>>> v  = simplify(ZeroExt(6, v0))
>>> v
2
>>> v.size()
8

Definition at line 4593 of file z3py.py.

4593def ZeroExt(n, a):
4594 """Return a bit-vector expression with `n` extra zero-bits.
4595
4596 >>> x = BitVec('x', 16)
4597 >>> n = ZeroExt(8, x)
4598 >>> n.size()
4599 24
4600 >>> n
4601 ZeroExt(8, x)
4602 >>> n.sort()
4603 BitVec(24)
4604 >>> v0 = BitVecVal(2, 2)
4605 >>> v0
4606 2
4607 >>> v0.size()
4608 2
4609 >>> v = simplify(ZeroExt(6, v0))
4610 >>> v
4611 2
4612 >>> v.size()
4613 8
4614 """
4615 if z3_debug():
4616 _z3_assert(_is_int(n), "First argument must be an integer")
4617 _z3_assert(is_bv(a), "Second argument must be a Z3 bit-vector expression")
4618 return BitVecRef(Z3_mk_zero_ext(a.ctx_ref(), n, a.as_ast()), a.ctx)
4619
4620
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 10109 of file z3py.py.

◆ _dflt_fpsort_sbits

int _dflt_fpsort_sbits = 53
protected

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

◆ _main_ctx

_main_ctx = None
protected

Definition at line 263 of file z3py.py.

◆ _my_hacky_class

_my_hacky_class = None
protected

Definition at line 12304 of file z3py.py.

◆ _on_clause_eh

_on_clause_eh = Z3_on_clause_eh(on_clause_eh)
protected

Definition at line 12312 of file z3py.py.

◆ _on_model_eh

_on_model_eh = on_model_eh_type(_global_on_model)
protected

Definition at line 8580 of file z3py.py.

◆ _on_models

dict _on_models = {}
protected

Definition at line 8572 of file z3py.py.

◆ _prop_closures

_prop_closures = None
protected

Definition at line 12361 of file z3py.py.

◆ _ROUNDING_MODES

_ROUNDING_MODES
protected
Initial value:
= frozenset({
Z3_OP_FPA_RM_TOWARD_ZERO,
Z3_OP_FPA_RM_TOWARD_NEGATIVE,
Z3_OP_FPA_RM_TOWARD_POSITIVE,
Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN,
Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY
})

Definition at line 10128 of file z3py.py.

◆ _user_prop_binding

_user_prop_binding = Z3_on_binding_eh(user_prop_binding)
protected

Definition at line 12467 of file z3py.py.

◆ _user_prop_created

_user_prop_created = Z3_created_eh(user_prop_created)
protected

Definition at line 12462 of file z3py.py.

◆ _user_prop_decide

_user_prop_decide = Z3_decide_eh(user_prop_decide)
protected

Definition at line 12466 of file z3py.py.

◆ _user_prop_diseq

_user_prop_diseq = Z3_eq_eh(user_prop_diseq)
protected

Definition at line 12465 of file z3py.py.

◆ _user_prop_eq

_user_prop_eq = Z3_eq_eh(user_prop_eq)
protected

Definition at line 12464 of file z3py.py.

◆ _user_prop_final

_user_prop_final = Z3_final_eh(user_prop_final)
protected

Definition at line 12463 of file z3py.py.

◆ _user_prop_fixed

_user_prop_fixed = Z3_fixed_eh(user_prop_fixed)
protected

Definition at line 12461 of file z3py.py.

◆ _user_prop_fresh

_user_prop_fresh = Z3_fresh_eh(user_prop_fresh)
protected

Definition at line 12460 of file z3py.py.

◆ _user_prop_pop

_user_prop_pop = Z3_pop_eh(user_prop_pop)
protected

Definition at line 12459 of file z3py.py.

◆ _user_prop_push

_user_prop_push = Z3_push_eh(user_prop_push)
protected

Definition at line 12458 of file z3py.py.

◆ sat

Definition at line 7543 of file z3py.py.

◆ unknown

Definition at line 7545 of file z3py.py.

◆ unsat

Definition at line 7544 of file z3py.py.

◆ Z3_DEBUG

Z3_DEBUG = __debug__

Definition at line 67 of file z3py.py.