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  ComplexSortRef
class  ComplexRef
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)
 is_complex_sort (s)
 is_complex (a)
 ComplexSort (ctx=None)
 Complex (name, ctx=None)
 Complexes (names, ctx=None)
 ComplexVal (real, imag=0, ctx=None)
 RealPart (value)
 ImagPart (value)
 _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 9237 of file z3py.py.

9237def _and_then(t1, t2, ctx=None):
9238 t1 = _to_tactic(t1, ctx)
9239 t2 = _to_tactic(t2, ctx)
9240 if z3_debug():
9241 _z3_assert(t1.ctx == t2.ctx, "Context mismatch")
9242 return Tactic(Z3_tactic_and_then(t1.ctx.ref(), t1.tactic, t2.tactic), t1.ctx)
9243
9244
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 4948 of file z3py.py.

4948def _array_select(ar, arg):
4949 if isinstance(arg, tuple):
4950 args = [ar.sort().domain_n(i).cast(arg[i]) for i in range(len(arg))]
4951 _args, sz = _to_ast_array(args)
4952 return _to_expr_ref(Z3_mk_select_n(ar.ctx_ref(), ar.as_ast(), sz, _args), ar.ctx)
4953 arg = ar.sort().domain().cast(arg)
4954 return _to_expr_ref(Z3_mk_select(ar.ctx_ref(), ar.as_ast(), arg.as_ast()), ar.ctx)
4955
4956
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 4470 of file z3py.py.

4470def _check_bv_args(a, b):
4471 if z3_debug():
4472 _z3_assert(is_bv(a) or is_bv(b), "First or second argument must be a Z3 bit-vector expression")
4473
4474

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

11381def _check_fp_args(a, b):
11382 if z3_debug():
11383 _z3_assert(is_fp(a) or is_fp(b), "First or second argument must be a Z3 floating-point expression")
11384
11385

◆ _check_same_sort()

_check_same_sort ( a,
b,
ctx = None )
protected

Definition at line 1305 of file z3py.py.

1305def _check_same_sort(a, b, ctx=None):
1306 if not isinstance(a, ExprRef):
1307 return False
1308 if not isinstance(b, ExprRef):
1309 return False
1310 if ctx is None:
1311 ctx = a.ctx
1312
1313 a_sort = Z3_get_sort(ctx.ctx, a.ast)
1314 b_sort = Z3_get_sort(ctx.ctx, b.ast)
1315 return Z3_is_eq_sort(ctx.ctx, a_sort, b_sort)
1316
1317
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 11827 of file z3py.py.

11827def _coerce_char(ch, ctx=None):
11828 if isinstance(ch, str):
11829 ctx = _get_ctx(ctx)
11830 ch = CharVal(ch, ctx)
11831 if not is_expr(ch):
11832 raise Z3Exception("Character expression expected")
11833 return ch
11834

◆ _coerce_expr_list()

_coerce_expr_list ( alist,
ctx = None )
protected

Definition at line 1357 of file z3py.py.

1357def _coerce_expr_list(alist, ctx=None):
1358 has_expr = False
1359 for a in alist:
1360 if is_expr(a):
1361 has_expr = True
1362 break
1363 if not has_expr:
1364 alist = [_py2expr(a, ctx) for a in alist]
1365 else:
1366 ctx = ctx if ctx is not None else _ctx_from_ast_arg_list(alist)
1367 alist = [ComplexVal(a, ctx=ctx) if isinstance(a, complex) else a for a in alist]
1368 s = _reduce(_coerce_expr_merge, alist, None)
1369 return [s.cast(a) for a in alist]
1370
1371

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

◆ _coerce_expr_merge()

_coerce_expr_merge ( s,
a )
protected

Definition at line 1287 of file z3py.py.

1287def _coerce_expr_merge(s, a):
1288 if is_expr(a):
1289 s1 = a.sort()
1290 if s is None:
1291 return s1
1292 if s1.eq(s):
1293 return s
1294 elif s.subsort(s1):
1295 return s1
1296 elif s1.subsort(s):
1297 return s
1298 else:
1299 if z3_debug():
1300 _z3_assert(s1.ctx == s.ctx, "context mismatch")
1301 _z3_assert(False, "sort mismatch")
1302 else:
1303 return s
1304

Referenced by _coerce_exprs().

◆ _coerce_exprs()

_coerce_exprs ( a,
b,
ctx = None )
protected

Definition at line 1318 of file z3py.py.

1318def _coerce_exprs(a, b, ctx=None):
1319 if not is_expr(a) and not is_expr(b):
1320 a = _py2expr(a, ctx)
1321 b = _py2expr(b, ctx)
1322 if isinstance(a, str) and isinstance(b, SeqRef):
1323 a = StringVal(a, b.ctx)
1324 if isinstance(b, str) and isinstance(a, SeqRef):
1325 b = StringVal(b, a.ctx)
1326 if isinstance(a, float) and isinstance(b, ArithRef):
1327 a = RealVal(a, b.ctx)
1328 if isinstance(b, float) and isinstance(a, ArithRef):
1329 b = RealVal(b, a.ctx)
1330 if isinstance(a, complex) and is_expr(b):
1331 a = ComplexVal(a, ctx=b.ctx)
1332 if isinstance(b, complex) and is_expr(a):
1333 b = ComplexVal(b, ctx=a.ctx)
1334
1335 if _check_same_sort(a, b, ctx):
1336 return (a, b)
1337
1338 if z3_debug():
1339 _z3_assert(is_expr(a) or is_expr(b), "At least one of the arguments must be a Z3 expression")
1340 # In x + 1 only x is an expression: its sort is the result sort, so only the
1341 # Python value needs to be cast.
1342 if not is_expr(b):
1343 return (a, a.sort().cast(b))
1344 if not is_expr(a):
1345 return (b.sort().cast(a), b)
1346 s = _coerce_expr_merge(_coerce_expr_merge(None, a), b)
1347 return (s.cast(a), s.cast(b))
1348
1349

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

10298def _coerce_fp_expr_list(alist, ctx):
10299 first_fp_sort = None
10300 for a in alist:
10301 if is_fp(a):
10302 if first_fp_sort is None:
10303 first_fp_sort = a.sort()
10304 elif first_fp_sort == a.sort():
10305 pass # OK, same as before
10306 else:
10307 # we saw at least 2 different float sorts; something will
10308 # throw a sort mismatch later, for now assume None.
10309 first_fp_sort = None
10310 break
10311
10312 r = []
10313 for i in range(len(alist)):
10314 a = alist[i]
10315 is_repr = isinstance(a, str) and a.contains("2**(") and a.endswith(")")
10316 if is_repr or _is_int(a) or isinstance(a, (float, bool)):
10317 r.append(FPVal(a, None, first_fp_sort, ctx))
10318 else:
10319 r.append(a)
10320 return _coerce_expr_list(r, ctx)
10321
10322
10323# FP Sorts
10324

◆ _coerce_seq()

_coerce_seq ( s,
ctx = None )
protected

Definition at line 11877 of file z3py.py.

11877def _coerce_seq(s, ctx=None):
11878 if isinstance(s, str):
11879 ctx = _get_ctx(ctx)
11880 s = StringVal(s, ctx)
11881 if not is_expr(s):
11882 raise Z3Exception("Non-expression passed as a sequence")
11883 if not is_seq(s):
11884 raise Z3Exception("Non-sequence passed as a sequence")
11885 return s
11886
11887

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 _coerce_expr_list(), _ctx_from_ast_args(), And(), ComplexVal(), 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 10294 of file z3py.py.

10294def _dflt_fps(ctx=None):
10295 return get_default_fp_sort(ctx)
10296
10297

◆ _dflt_rm()

_dflt_rm ( ctx = None)
protected

Definition at line 10290 of file z3py.py.

10290def _dflt_rm(ctx=None):
10291 return get_default_rounding_mode(ctx)
10292
10293

◆ _dict2darray()

_dict2darray ( decls,
ctx )
protected

Definition at line 10163 of file z3py.py.

10163def _dict2darray(decls, ctx):
10164 sz = len(decls)
10165 _names = (Symbol * sz)()
10166 _decls = (FuncDecl * sz)()
10167 i = 0
10168 for k in decls:
10169 v = decls[k]
10170 if z3_debug():
10171 _z3_assert(isinstance(k, str), "String expected")
10172 _z3_assert(is_func_decl(v) or is_const(v), "Z3 declaration or constant expected")
10173 _names[i] = to_symbol(k, ctx)
10174 if is_const(v):
10175 _decls[i] = v.decl().ast
10176 else:
10177 _decls[i] = v.ast
10178 i = i + 1
10179 return sz, _names, _decls
10180

◆ _dict2sarray()

_dict2sarray ( sorts,
ctx )
protected

Definition at line 10147 of file z3py.py.

10147def _dict2sarray(sorts, ctx):
10148 sz = len(sorts)
10149 _names = (Symbol * sz)()
10150 _sorts = (Sort * sz)()
10151 i = 0
10152 for k in sorts:
10153 v = sorts[k]
10154 if z3_debug():
10155 _z3_assert(isinstance(k, str), "String expected")
10156 _z3_assert(is_sort(v), "Z3 sort expected")
10157 _names[i] = to_symbol(k, ctx)
10158 _sorts[i] = v.ast
10159 i = i + 1
10160 return sz, _names, _sorts
10161
10162

◆ _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

◆ _get_ctx2()

_get_ctx2 ( a,
b,
ctx = None )
protected

Definition at line 11888 of file z3py.py.

11888def _get_ctx2(a, b, ctx=None):
11889 if is_expr(a):
11890 return a.ctx
11891 if is_expr(b):
11892 return b.ctx
11893 if ctx is None:
11894 ctx = main_ctx()
11895 return ctx
11896
11897

◆ _global_on_model()

_global_on_model ( ctx)
protected

Definition at line 8708 of file z3py.py.

8708def _global_on_model(ctx):
8709 (fn, mdl) = _on_models[ctx]
8710 fn(mdl)
8711
8712

◆ _has_probe()

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

Definition at line 2001 of file z3py.py.

2001def _has_probe(args):
2002 """Return `True` if one of the elements of the given collection is a Z3 probe."""
2003 for arg in args:
2004 if is_probe(arg):
2005 return True
2006 return False
2007
2008

Referenced by And(), and Or().

◆ _is_algebraic()

_is_algebraic ( ctx,
a )
protected

Definition at line 2910 of file z3py.py.

2910def _is_algebraic(ctx, a):
2911 return Z3_is_algebraic_number(ctx.ref(), a)
2912
2913
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 2906 of file z3py.py.

2906def _is_numeral(ctx, a):
2907 return Z3_is_numeral_ast(ctx.ref(), a)
2908
2909
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 1558 of file z3py.py.

1558def _mk_bin(f, a, b):
1559 args = (Ast * 2)()
1560 if z3_debug():
1561 _z3_assert(a.ctx == b.ctx, "Context mismatch")
1562 args[0] = a.as_ast()
1563 args[1] = b.as_ast()
1564 return f(a.ctx.ref(), 2, args)
1565
1566

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

11169def _mk_fp_bin(f, rm, a, b, ctx):
11170 ctx = _get_ctx(ctx)
11171 [a, b] = _coerce_fp_expr_list([a, b], ctx)
11172 if z3_debug():
11173 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
11174 _z3_assert(is_fp(a) or is_fp(b), "Second or third argument must be a Z3 floating-point expression")
11175 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast()), ctx)
11176
11177

◆ _mk_fp_bin_norm()

_mk_fp_bin_norm ( f,
a,
b,
ctx )
protected

Definition at line 11178 of file z3py.py.

11178def _mk_fp_bin_norm(f, a, b, ctx):
11179 ctx = _get_ctx(ctx)
11180 [a, b] = _coerce_fp_expr_list([a, b], ctx)
11181 if z3_debug():
11182 _z3_assert(is_fp(a) or is_fp(b), "First or second argument must be a Z3 floating-point expression")
11183 return FPRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
11184
11185

◆ _mk_fp_bin_pred()

_mk_fp_bin_pred ( f,
a,
b,
ctx )
protected

Definition at line 11186 of file z3py.py.

11186def _mk_fp_bin_pred(f, a, b, ctx):
11187 ctx = _get_ctx(ctx)
11188 [a, b] = _coerce_fp_expr_list([a, b], ctx)
11189 if z3_debug():
11190 _z3_assert(is_fp(a) or is_fp(b), "First or second argument must be a Z3 floating-point expression")
11191 return BoolRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
11192
11193

◆ _mk_fp_tern()

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

Definition at line 11194 of file z3py.py.

11194def _mk_fp_tern(f, rm, a, b, c, ctx):
11195 ctx = _get_ctx(ctx)
11196 [a, b, c] = _coerce_fp_expr_list([a, b, c], ctx)
11197 if z3_debug():
11198 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
11199 _z3_assert(is_fp(a) or is_fp(b) or is_fp(
11200 c), "Second, third or fourth argument must be a Z3 floating-point expression")
11201 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
11202
11203

◆ _mk_fp_unary()

_mk_fp_unary ( f,
rm,
a,
ctx )
protected

Definition at line 11152 of file z3py.py.

11152def _mk_fp_unary(f, rm, a, ctx):
11153 ctx = _get_ctx(ctx)
11154 [a] = _coerce_fp_expr_list([a], ctx)
11155 if z3_debug():
11156 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
11157 _z3_assert(is_fp(a), "Second argument must be a Z3 floating-point expression")
11158 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast()), ctx)
11159
11160

◆ _mk_fp_unary_pred()

_mk_fp_unary_pred ( f,
a,
ctx )
protected

Definition at line 11161 of file z3py.py.

11161def _mk_fp_unary_pred(f, a, ctx):
11162 ctx = _get_ctx(ctx)
11163 [a] = _coerce_fp_expr_list([a], ctx)
11164 if z3_debug():
11165 _z3_assert(is_fp(a), "First argument must be a Z3 floating-point expression")
11166 return BoolRef(f(ctx.ref(), a.as_ast()), ctx)
11167
11168

◆ _mk_quantifier()

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

Definition at line 2358 of file z3py.py.

2358def _mk_quantifier(is_forall, vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2359 if z3_debug():
2360 _z3_assert(is_bool(body) or is_app(vs) or (len(vs) > 0 and is_app(vs[0])), "Z3 expression expected")
2361 _z3_assert(is_const(vs) or (len(vs) > 0 and all([is_const(v) for v in vs])), "Invalid bounded variable(s)")
2362 _z3_assert(all([is_pattern(a) or is_expr(a) for a in patterns]), "Z3 patterns expected")
2363 _z3_assert(all([is_expr(p) for p in no_patterns]), "no patterns are Z3 expressions")
2364 if is_app(vs):
2365 ctx = vs.ctx
2366 vs = [vs]
2367 else:
2368 ctx = vs[0].ctx
2369 if not is_expr(body):
2370 body = BoolVal(body, ctx)
2371 num_vars = len(vs)
2372 if num_vars == 0:
2373 return body
2374 _vs = (Ast * num_vars)()
2375 for i in range(num_vars):
2376 # TODO: Check if is constant
2377 _vs[i] = vs[i].as_ast()
2378 patterns = [_to_pattern(p) for p in patterns]
2379 num_pats = len(patterns)
2380 _pats = (Pattern * num_pats)()
2381 for i in range(num_pats):
2382 _pats[i] = patterns[i].ast
2383 _no_pats, num_no_pats = _to_ast_array(no_patterns)
2384 qid = to_symbol(qid, ctx)
2385 skid = to_symbol(skid, ctx)
2386 return QuantifierRef(Z3_mk_quantifier_const_ex(ctx.ref(), is_forall, weight, qid, skid,
2387 num_vars, _vs,
2388 num_pats, _pats,
2389 num_no_pats, _no_pats,
2390 body.as_ast()), ctx)
2391
2392
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 9245 of file z3py.py.

9245def _or_else(t1, t2, ctx=None):
9246 t1 = _to_tactic(t1, ctx)
9247 t2 = _to_tactic(t2, ctx)
9248 if z3_debug():
9249 _z3_assert(t1.ctx == t2.ctx, "Context mismatch")
9250 return Tactic(Z3_tactic_or_else(t1.ctx.ref(), t1.tactic, t2.tactic), t1.ctx)
9251
9252
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 9936 of file z3py.py.

9936def _pb_args_coeffs(args, default_ctx=None):
9937 args = _get_args_ast_list(args)
9938 if len(args) == 0:
9939 return _get_ctx(default_ctx), 0, (Ast * 0)(), (ctypes.c_int * 0)()
9940 args = [_reorder_pb_arg(arg) for arg in args]
9941 args, coeffs = zip(*args)
9942 if z3_debug():
9943 _z3_assert(len(args) > 0, "Non empty list of arguments expected")
9944 ctx = _ctx_from_ast_arg_list(args)
9945 if z3_debug():
9946 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
9947 args = _coerce_expr_list(args, ctx)
9948 _args, sz = _to_ast_array(args)
9949 _coeffs = (ctypes.c_int * len(coeffs))()
9950 for i in range(len(coeffs)):
9951 _z3_check_cint_overflow(coeffs[i], "coefficient")
9952 _coeffs[i] = coeffs[i]
9953 return ctx, sz, _args, _coeffs, args
9954
9955

◆ _probe_and()

_probe_and ( args,
ctx )
protected

Definition at line 9660 of file z3py.py.

9660def _probe_and(args, ctx):
9661 return _probe_nary(Z3_probe_and, args, ctx)
9662
9663

Referenced by And().

◆ _probe_nary()

_probe_nary ( f,
args,
ctx )
protected

Definition at line 9650 of file z3py.py.

9650def _probe_nary(f, args, ctx):
9651 if z3_debug():
9652 _z3_assert(len(args) > 0, "At least one argument expected")
9653 num = len(args)
9654 r = _to_probe(args[0], ctx)
9655 for i in range(num - 1):
9656 r = Probe(f(ctx.ref(), r.probe, _to_probe(args[i + 1], ctx).probe), ctx)
9657 return r
9658
9659

◆ _probe_or()

_probe_or ( args,
ctx )
protected

Definition at line 9664 of file z3py.py.

9664def _probe_or(args, ctx):
9665 return _probe_nary(Z3_probe_or, args, ctx)
9666
9667

Referenced by Or().

◆ _prove_html()

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

Definition at line 10127 of file z3py.py.

10127def _prove_html(claim, show=False, **keywords):
10128 """Version of function `prove` that renders HTML."""
10129 if z3_debug():
10130 _z3_assert(is_bool(claim), "Z3 Boolean expression expected")
10131 s = Solver()
10132 s.set(**keywords)
10133 s.add(Not(claim))
10134 if show:
10135 print(s)
10136 r = s.check()
10137 if r == unsat:
10138 print("<b>proved</b>")
10139 elif r == unknown:
10140 print("<b>failed to prove</b>")
10141 print(s.model())
10142 else:
10143 print("<b>counterexample</b>")
10144 print(s.model())
10145
10146

◆ _py2expr()

_py2expr ( a,
ctx = None )
protected

Definition at line 3402 of file z3py.py.

3402def _py2expr(a, ctx=None):
3403 if isinstance(a, bool):
3404 return BoolVal(a, ctx)
3405 if _is_int(a):
3406 return IntVal(a, ctx)
3407 if isinstance(a, float):
3408 return RealVal(a, ctx)
3409 if isinstance(a, complex):
3410 return ComplexVal(a, ctx=ctx)
3411 if isinstance(a, str):
3412 return StringVal(a, ctx)
3413 if is_expr(a):
3414 return a
3415 if z3_debug():
3416 _z3_assert(False, "Python bool, int, long or float expected")
3417
3418

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

1350def _reduce(func, sequence, initial):
1351 result = initial
1352 for element in sequence:
1353 result = func(result, element)
1354 return result
1355
1356

Referenced by _coerce_expr_list().

◆ _reorder_pb_arg()

_reorder_pb_arg ( arg)
protected

Definition at line 9929 of file z3py.py.

9929def _reorder_pb_arg(arg):
9930 a, b = arg
9931 if not _is_int(b) and _is_int(a):
9932 return b, a
9933 return arg
9934
9935

◆ _solve_html()

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

Definition at line 10078 of file z3py.py.

10078def _solve_html(*args, **keywords):
10079 """Version of function `solve` that renders HTML output."""
10080 show = keywords.pop("show", False)
10081 s = Solver()
10082 s.set(**keywords)
10083 s.add(*args)
10084 if show:
10085 print("<b>Problem:</b>")
10086 print(s)
10087 r = s.check()
10088 if r == unsat:
10089 print("<b>no solution</b>")
10090 elif r == unknown:
10091 print("<b>failed to solve</b>")
10092 try:
10093 print(s.model())
10094 except Z3Exception:
10095 return
10096 else:
10097 if show:
10098 print("<b>Solution:</b>")
10099 print(s.model())
10100
10101

◆ _solve_using_html()

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

Definition at line 10102 of file z3py.py.

10102def _solve_using_html(s, *args, **keywords):
10103 """Version of function `solve_using` that renders HTML."""
10104 show = keywords.pop("show", False)
10105 if z3_debug():
10106 _z3_assert(isinstance(s, Solver), "Solver object expected")
10107 s.set(**keywords)
10108 s.add(*args)
10109 if show:
10110 print("<b>Problem:</b>")
10111 print(s)
10112 r = s.check()
10113 if r == unsat:
10114 print("<b>no solution</b>")
10115 elif r == unknown:
10116 print("<b>failed to solve</b>")
10117 try:
10118 print(s.model())
10119 except Z3Exception:
10120 return
10121 else:
10122 if show:
10123 print("<b>Solution:</b>")
10124 print(s.model())
10125
10126

◆ _sort()

SortRef _sort ( Context ctx,
Any a )
protected

Definition at line 733 of file z3py.py.

733def _sort(ctx : Context, a : Any) -> SortRef:
734 return _to_sort_ref(Z3_get_sort(ctx.ref(), a), ctx)
735
736

◆ _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(Sort.from_buffer_copy(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 1229 of file z3py.py.

1229def _to_expr_ref(a, ctx):
1230 if isinstance(a, Pattern):
1231 return PatternRef(a, ctx)
1232 ctx_ref = ctx.ref()
1233 k = Z3_get_ast_kind(ctx_ref, a)
1234 if k == Z3_QUANTIFIER_AST:
1235 return QuantifierRef(a, ctx)
1236 # Check for finite set sort before checking sort kind
1237 s = Z3_get_sort(ctx_ref, a)
1238 if Z3_is_finite_set_sort(ctx_ref, s):
1239 return FiniteSetRef(a, ctx)
1240 sk = Z3_get_sort_kind(ctx_ref, s)
1241 if sk == Z3_BOOL_SORT:
1242 return BoolRef(a, ctx)
1243 if sk == Z3_INT_SORT:
1244 if k == Z3_NUMERAL_AST:
1245 return IntNumRef(a, ctx)
1246 return ArithRef(a, ctx)
1247 if sk == Z3_REAL_SORT:
1248 if k == Z3_NUMERAL_AST:
1249 return RatNumRef(a, ctx)
1250 if _is_algebraic(ctx, a):
1251 return AlgebraicNumRef(a, ctx)
1252 return ArithRef(a, ctx)
1253 if sk == Z3_COMPLEX_SORT:
1254 return ComplexRef(a, ctx)
1255 if sk == Z3_BV_SORT:
1256 if k == Z3_NUMERAL_AST:
1257 return BitVecNumRef(a, ctx)
1258 else:
1259 return BitVecRef(a, ctx)
1260 if sk == Z3_ARRAY_SORT:
1261 return ArrayRef(a, ctx)
1262 if sk == Z3_DATATYPE_SORT:
1263 return DatatypeRef(a, ctx)
1264 if sk == Z3_FLOATING_POINT_SORT:
1265 if k == Z3_APP_AST and _is_numeral(ctx, a):
1266 return FPNumRef(a, ctx)
1267 else:
1268 return FPRef(a, ctx)
1269 if sk == Z3_FINITE_FIELD_SORT:
1270 return FiniteFieldRef(a, ctx)
1271 if sk == Z3_FINITE_DOMAIN_SORT:
1272 if k == Z3_NUMERAL_AST:
1273 return FiniteDomainNumRef(a, ctx)
1274 else:
1275 return FiniteDomainRef(a, ctx)
1276 if sk == Z3_ROUNDING_MODE_SORT:
1277 return FPRMRef(a, ctx)
1278 if sk == Z3_SEQ_SORT:
1279 return SeqRef(a, ctx)
1280 if sk == Z3_CHAR_SORT:
1281 return CharRef(a, ctx)
1282 if sk == Z3_RE_SORT:
1283 return ReRef(a, ctx)
1284 return ExprRef(a, ctx)
1285
1286
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 ArithRef.__add__(), FuncDeclRef.__call__(), ArithRef.__div__(), ArithRef.__mul__(), ArithRef.__neg__(), ArithRef.__radd__(), ArithRef.__rdiv__(), ArithRef.__rmul__(), ArithRef.__rsub__(), ArithRef.__sub__(), _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(), ImagPart(), QuantifierRef.no_pattern(), ModelRef.project(), ModelRef.project_with_witness(), RealPart(), Update(), ExprRef.update(), DatatypeRef.update_field(), FuncEntry.value(), and Var().

◆ _to_float_str()

_to_float_str ( val,
exp = 0 )
protected

Definition at line 10882 of file z3py.py.

10882def _to_float_str(val, exp=0):
10883 if isinstance(val, float):
10884 if math.isnan(val):
10885 res = "NaN"
10886 elif val == 0.0:
10887 sone = math.copysign(1.0, val)
10888 if sone < 0.0:
10889 return "-0.0"
10890 else:
10891 return "+0.0"
10892 elif val == float("+inf"):
10893 res = "+oo"
10894 elif val == float("-inf"):
10895 res = "-oo"
10896 else:
10897 v = val.as_integer_ratio()
10898 num = v[0]
10899 den = v[1]
10900 rvs = str(num) + "/" + str(den)
10901 res = rvs
10902 elif isinstance(val, bool):
10903 if val:
10904 res = "1.0"
10905 else:
10906 res = "0.0"
10907 elif _is_int(val):
10908 res = str(val)
10909 elif isinstance(val, str):
10910 inx = val.find("*(2**")
10911 if inx == -1:
10912 res = val
10913 if exp != 0:
10914 inx = val.lower().find("p")
10915 if inx != -1:
10916 res = val[:inx]
10917 exp = int(val[inx + 1:]) + int(exp)
10918 elif val[-1] == ")":
10919 res = val[0:inx]
10920 exp = str(int(val[inx + 5:-1]) + int(exp))
10921 else:
10922 _z3_assert(False, "String does not have floating-point numeral form.")
10923 elif z3_debug():
10924 _z3_assert(False, "Python value cannot be used to create floating-point numerals.")
10925 if exp == 0:
10926 return res
10927 else:
10928 return res + "p" + str(exp)
10929
10930

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

970def _to_func_decl_ref(a, ctx):
971 return FuncDeclRef(a, ctx)
972
973

Referenced by _to_ast_ref().

◆ _to_goal()

_to_goal ( a)
protected

Definition at line 9221 of file z3py.py.

9221def _to_goal(a):
9222 if isinstance(a, BoolRef):
9223 goal = Goal(ctx=a.ctx)
9224 goal.add(a)
9225 return goal
9226 else:
9227 return a
9228
9229

◆ _to_int_str()

_to_int_str ( val)
protected

Definition at line 3453 of file z3py.py.

3453def _to_int_str(val):
3454 if isinstance(val, float):
3455 return str(int(val))
3456 elif isinstance(val, bool):
3457 if val:
3458 return "1"
3459 else:
3460 return "0"
3461 else:
3462 return str(val)
3463
3464

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

2136def _to_pattern(arg):
2137 if is_pattern(arg):
2138 return arg
2139 else:
2140 return MultiPattern(arg)
2141

Referenced by _mk_quantifier().

◆ _to_probe()

_to_probe ( p,
ctx = None )
protected

Definition at line 9604 of file z3py.py.

9604def _to_probe(p, ctx=None):
9605 if is_probe(p):
9606 return p
9607 else:
9608 return Probe(p, ctx)
9609
9610

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

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

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

9230def _to_tactic(t, ctx=None):
9231 if isinstance(t, Tactic):
9232 return t
9233 else:
9234 return Tactic(t, ctx)
9235
9236

◆ _valid_accessor()

_valid_accessor ( acc)
protected

Datatypes.

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

Definition at line 5636 of file z3py.py.

5636def _valid_accessor(acc):
5637 """Return `True` if acc is pair of the form (String, Datatype or Sort). """
5638 if not isinstance(acc, tuple):
5639 return False
5640 if len(acc) != 2:
5641 return False
5642 return isinstance(acc[0], str) and (isinstance(acc[1], Datatype) or is_sort(acc[1]))
5643
5644

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(), _coerce_exprs(), _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(), ComplexVal(), 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(), ImagPart(), IsInt(), K(), ExprRef.kind(), Map(), MultiPattern(), QuantifierRef.no_pattern(), ExprRef.num_args(), Or(), QuantifierRef.pattern(), RatVal(), RealPart(), 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 9888 of file z3py.py.

9888def Abs(arg):
9889 """Create the absolute value of an arithmetic expression"""
9890 return If(arg > 0, arg, -arg)
9891
9892

Referenced by ArithRef.__abs__().

◆ AllChar()

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

Definition at line 12386 of file z3py.py.

12386def AllChar(regex_sort, ctx=None):
12387 """Create a regular expression that accepts all single character strings
12388 """
12389 return ReRef(Z3_mk_re_allchar(regex_sort.ctx_ref(), regex_sort.ast), regex_sort.ctx)
12390
12391# Special Relations
12392
12393
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 2009 of file z3py.py.

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

9253def AndThen(*ts, **ks):
9254 """Return a tactic that applies the tactics in `*ts` in sequence.
9255
9256 >>> x, y = Ints('x y')
9257 >>> t = AndThen(Tactic('simplify'), Tactic('solve-eqs'))
9258 >>> t(And(x == 0, y > x + 1))
9259 [[Not(y <= 1)]]
9260 >>> t(And(x == 0, y > x + 1)).as_expr()
9261 Not(y <= 1)
9262 """
9263 if z3_debug():
9264 _z3_assert(len(ts) >= 2, "At least two arguments expected")
9265 ctx = ks.get("ctx", None)
9266 num = len(ts)
9267 r = ts[0]
9268 for i in range(num - 1):
9269 r = _and_then(r, ts[i + 1], ctx)
9270 return r
9271
9272

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

6195def args2params(arguments, keywords, ctx=None):
6196 """Convert python arguments into a Z3_params object.
6197 A ':' is added to the keywords, and '_' is replaced with '-'
6198
6199 >>> args2params(['model', True, 'relevancy', 2], {'elim_and' : True})
6200 (params model true relevancy 2 elim_and true)
6201 """
6202 if z3_debug():
6203 _z3_assert(len(arguments) % 2 == 0, "Argument list must have an even number of elements.")
6204 prev = None
6205 r = ParamsRef(ctx)
6206 for a in arguments:
6207 if prev is None:
6208 prev = a
6209 else:
6210 r.set(prev, a)
6211 prev = None
6212 for k in keywords:
6213 v = keywords[k]
6214 r.set(k, v)
6215 return r
6216
6217

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

5085def Array(name, *sorts):
5086 """Return an array constant named `name` with the given domain and range sorts.
5087
5088 >>> a = Array('a', IntSort(), IntSort())
5089 >>> a.sort()
5090 Array(Int, Int)
5091 >>> a[0]
5092 a[0]
5093 """
5094 s = ArraySort(sorts)
5095 ctx = s.ctx
5096 return ArrayRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), s.ast), ctx)
5097
5098
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 5050 of file z3py.py.

5050def ArraySort(*sig):
5051 """Return the Z3 array sort with the given domain and range sorts.
5052
5053 >>> A = ArraySort(IntSort(), BoolSort())
5054 >>> A
5055 Array(Int, Bool)
5056 >>> A.domain()
5057 Int
5058 >>> A.range()
5059 Bool
5060 >>> AA = ArraySort(IntSort(), A)
5061 >>> AA
5062 Array(Int, Array(Int, Bool))
5063 >>> ArraySort(IntSort(), BoolSort(), RealSort())
5064 Array(Int, Bool, Real)
5065 """
5066 sig = _get_args(sig)
5067 if z3_debug():
5068 _z3_assert(len(sig) > 1, "At least two arguments expected")
5069 arity = len(sig) - 1
5070 r = sig[arity]
5071 d = sig[0]
5072 if z3_debug():
5073 for s in sig:
5074 _z3_assert(is_sort(s), "Z3 sort expected")
5075 _z3_assert(s.ctx == r.ctx, "Context mismatch")
5076 ctx = d.ctx
5077 if len(sig) == 2:
5078 return ArraySortRef(Z3_mk_array_sort(ctx.ref(), d.ast, r.ast), ctx)
5079 dom = (Sort * arity)()
5080 for i in range(arity):
5081 dom[i] = sig[i].ast
5082 return ArraySortRef(Z3_mk_array_sort_n(ctx.ref(), arity, dom, r.ast), ctx)
5083
5084
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 5232 of file z3py.py.

5232def AsArray(f):
5233 """Return a Z3 as-array expression for the given function declaration.
5234
5235 >>> f = Function('f', IntSort(), IntSort())
5236 >>> a = AsArray(f)
5237 >>> a.sort()
5238 Array(Int, Int)
5239 >>> is_as_array(a)
5240 True
5241 >>> get_as_array_func(a) == f
5242 True
5243 """
5244 if z3_debug():
5245 _z3_assert(isinstance(f, FuncDeclRef), "function declaration expected")
5246 ctx = f.ctx
5247 return ArrayRef(Z3_mk_as_array(ctx.ref(), f.ast), ctx)
5248
5249
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 9911 of file z3py.py.

9911def AtLeast(*args):
9912 """Create an at-least Pseudo-Boolean k constraint.
9913
9914 >>> a, b, c = Bools('a b c')
9915 >>> f = AtLeast(a, b, c, 2)
9916 """
9917 args = _get_args(args)
9918 if z3_debug():
9919 _z3_assert(len(args) > 1, "Non empty list of arguments expected")
9920 ctx = _ctx_from_ast_arg_list(args)
9921 if z3_debug():
9922 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
9923 args1 = _coerce_expr_list(args[:-1], ctx)
9924 k = args[-1]
9925 _args, sz = _to_ast_array(args1)
9926 return BoolRef(Z3_mk_atleast(ctx.ref(), sz, _args, k), ctx)
9927
9928
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 9893 of file z3py.py.

9893def AtMost(*args):
9894 """Create an at-most Pseudo-Boolean k constraint.
9895
9896 >>> a, b, c = Bools('a b c')
9897 >>> f = AtMost(a, b, c, 2)
9898 """
9899 args = _get_args(args)
9900 if z3_debug():
9901 _z3_assert(len(args) > 1, "Non empty list of arguments expected")
9902 ctx = _ctx_from_ast_arg_list(args)
9903 if z3_debug():
9904 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
9905 args1 = _coerce_expr_list(args[:-1], ctx)
9906 k = args[-1]
9907 _args, sz = _to_ast_array(args1)
9908 return BoolRef(Z3_mk_atmost(ctx.ref(), sz, _args, k), ctx)
9909
9910
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 4325 of file z3py.py.

4325def BitVec(name, bv, ctx=None):
4326 """Return a bit-vector constant named `name`. `bv` may be the number of bits of a bit-vector sort.
4327 If `ctx=None`, then the global context is used.
4328
4329 >>> x = BitVec('x', 16)
4330 >>> is_bv(x)
4331 True
4332 >>> x.size()
4333 16
4334 >>> x.sort()
4335 BitVec(16)
4336 >>> word = BitVecSort(16)
4337 >>> x2 = BitVec('x', word)
4338 >>> eq(x, x2)
4339 True
4340 """
4341 if isinstance(bv, BitVecSortRef):
4342 ctx = bv.ctx
4343 else:
4344 ctx = _get_ctx(ctx)
4345 bv = BitVecSort(bv, ctx)
4346 return BitVecRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), bv.ast), ctx)
4347
4348

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

4349def BitVecs(names, bv, ctx=None):
4350 """Return a tuple of bit-vector constants of size bv.
4351
4352 >>> x, y, z = BitVecs('x y z', 16)
4353 >>> x.size()
4354 16
4355 >>> x.sort()
4356 BitVec(16)
4357 >>> Sum(x, y, z)
4358 0 + x + y + z
4359 >>> Product(x, y, z)
4360 1*x*y*z
4361 >>> simplify(Product(x, y, z))
4362 x*y*z
4363 """
4364 ctx = _get_ctx(ctx)
4365 if isinstance(names, str):
4366 names = names.split(" ")
4367 return [BitVec(name, bv, ctx) for name in names]
4368
4369

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

4293def BitVecSort(sz, ctx=None):
4294 """Return a Z3 bit-vector sort of the given size. If `ctx=None`, then the global context is used.
4295
4296 >>> Byte = BitVecSort(8)
4297 >>> Word = BitVecSort(16)
4298 >>> Byte
4299 BitVec(8)
4300 >>> x = Const('x', Byte)
4301 >>> eq(x, BitVec('x', 8))
4302 True
4303 """
4304 ctx = _get_ctx(ctx)
4305 return BitVecSortRef(Z3_mk_bv_sort(ctx.ref(), sz), ctx)
4306
4307
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 4308 of file z3py.py.

4308def BitVecVal(val, bv, ctx=None):
4309 """Return a bit-vector value with the given number of bits. If `ctx=None`, then the global context is used.
4310
4311 >>> v = BitVecVal(10, 32)
4312 >>> v
4313 10
4314 >>> print("0x%.8x" % v.as_long())
4315 0x0000000a
4316 """
4317 if is_bv_sort(bv):
4318 ctx = bv.ctx
4319 return BitVecNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), bv.ast), ctx)
4320 else:
4321 ctx = _get_ctx(ctx)
4322 return BitVecNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), BitVecSort(bv, ctx).ast), ctx)
4323
4324
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 1888 of file z3py.py.

1888def Bool(name, ctx=None):
1889 """Return a Boolean constant named `name`. If `ctx=None`, then the global context is used.
1890
1891 >>> p = Bool('p')
1892 >>> q = Bool('q')
1893 >>> And(p, q)
1894 And(p, q)
1895 """
1896 ctx = _get_ctx(ctx)
1897 return BoolRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), BoolSort(ctx).ast), ctx)
1898
1899

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

1900def Bools(names, ctx=None):
1901 """Return a tuple of Boolean constants.
1902
1903 `names` is a single string containing all names separated by blank spaces.
1904 If `ctx=None`, then the global context is used.
1905
1906 >>> p, q, r = Bools('p q r')
1907 >>> And(p, Or(q, r))
1908 And(p, Or(q, r))
1909 """
1910 ctx = _get_ctx(ctx)
1911 if isinstance(names, str):
1912 names = names.split(" ")
1913 return [Bool(name, ctx) for name in names]
1914
1915

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

1851def BoolSort(ctx=None):
1852 """Return the Boolean Z3 sort. If `ctx=None`, then the global context is used.
1853
1854 >>> BoolSort()
1855 Bool
1856 >>> p = Const('p', BoolSort())
1857 >>> is_bool(p)
1858 True
1859 >>> r = Function('r', IntSort(), IntSort(), BoolSort())
1860 >>> r(0, 1)
1861 r(0, 1)
1862 >>> is_bool(r(0, 1))
1863 True
1864 """
1865 ctx = _get_ctx(ctx)
1866 return BoolSortRef(Z3_mk_bool_sort(ctx.ref()), ctx)
1867
1868
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 1869 of file z3py.py.

1869def BoolVal(val, ctx=None):
1870 """Return the Boolean value `True` or `False`. If `ctx=None`, then the global context is used.
1871
1872 >>> BoolVal(True)
1873 True
1874 >>> is_true(BoolVal(True))
1875 True
1876 >>> is_true(True)
1877 False
1878 >>> is_false(BoolVal(False))
1879 True
1880 """
1881 ctx = _get_ctx(ctx)
1882 if val:
1883 return BoolRef(Z3_mk_true(ctx.ref()), ctx)
1884 else:
1885 return BoolRef(Z3_mk_false(ctx.ref()), ctx)
1886
1887
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 1916 of file z3py.py.

1916def BoolVector(prefix, sz, ctx=None):
1917 """Return a list of Boolean constants of size `sz`.
1918
1919 The constants are named using the given prefix.
1920 If `ctx=None`, then the global context is used.
1921
1922 >>> P = BoolVector('p', 3)
1923 >>> P
1924 [p__0, p__1, p__2]
1925 >>> And(P)
1926 And(p__0, p__1, p__2)
1927 """
1928 return [Bool("%s__%s" % (prefix, i)) for i in range(sz)]
1929
1930

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

4261def BV2Int(a, is_signed=False):
4262 """Return the Z3 expression BV2Int(a).
4263
4264 >>> b = BitVec('b', 3)
4265 >>> BV2Int(b).sort()
4266 Int
4267 >>> x = Int('x')
4268 >>> x > BV2Int(b)
4269 x > BV2Int(b)
4270 >>> x > BV2Int(b, is_signed=False)
4271 x > BV2Int(b)
4272 >>> x > BV2Int(b, is_signed=True)
4273 x > If(b < 0, BV2Int(b) - 8, BV2Int(b))
4274 >>> solve(x > BV2Int(b), b == 1, x < 3)
4275 [x = 2, b = 1]
4276 """
4277 if z3_debug():
4278 _z3_assert(is_bv(a), "First argument must be a Z3 bit-vector expression")
4279 ctx = a.ctx
4280 # investigate problem with bv2int
4281 return ArithRef(Z3_mk_bv2int(ctx.ref(), a.as_ast(), is_signed), ctx)
4282
4283
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 4809 of file z3py.py.

4809def BVAddNoOverflow(a, b, signed):
4810 """A predicate the determines that bit-vector addition does not overflow"""
4811 _check_bv_args(a, b)
4812 a, b = _coerce_exprs(a, b)
4813 return BoolRef(Z3_mk_bvadd_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast(), signed), a.ctx)
4814
4815
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 4816 of file z3py.py.

4816def BVAddNoUnderflow(a, b):
4817 """A predicate the determines that signed bit-vector addition does not underflow"""
4818 _check_bv_args(a, b)
4819 a, b = _coerce_exprs(a, b)
4820 return BoolRef(Z3_mk_bvadd_no_underflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4821
4822
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 4851 of file z3py.py.

4851def BVMulNoOverflow(a, b, signed):
4852 """A predicate the determines that bit-vector multiplication does not overflow"""
4853 _check_bv_args(a, b)
4854 a, b = _coerce_exprs(a, b)
4855 return BoolRef(Z3_mk_bvmul_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast(), signed), a.ctx)
4856
4857
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 4858 of file z3py.py.

4858def BVMulNoUnderflow(a, b):
4859 """A predicate the determines that bit-vector signed multiplication does not underflow"""
4860 _check_bv_args(a, b)
4861 a, b = _coerce_exprs(a, b)
4862 return BoolRef(Z3_mk_bvmul_no_underflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4863
4864
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 4770 of file z3py.py.

4770def BvNand(a, b):
4771 """Return the bitwise NAND of `a` and `b`.
4772
4773 >>> x = BitVec('x', 8)
4774 >>> y = BitVec('y', 8)
4775 >>> BvNand(x, y)
4776 bvnand(x, y)
4777 """
4778 _check_bv_args(a, b)
4779 a, b = _coerce_exprs(a, b)
4780 return BitVecRef(Z3_mk_bvnand(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4781
4782
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 4783 of file z3py.py.

4783def BvNor(a, b):
4784 """Return the bitwise NOR of `a` and `b`.
4785
4786 >>> x = BitVec('x', 8)
4787 >>> y = BitVec('y', 8)
4788 >>> BvNor(x, y)
4789 bvnor(x, y)
4790 """
4791 _check_bv_args(a, b)
4792 a, b = _coerce_exprs(a, b)
4793 return BitVecRef(Z3_mk_bvnor(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4794
4795
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 4756 of file z3py.py.

4756def BVRedAnd(a):
4757 """Return the reduction-and expression of `a`."""
4758 if z3_debug():
4759 _z3_assert(is_bv(a), "First argument must be a Z3 bit-vector expression")
4760 return BitVecRef(Z3_mk_bvredand(a.ctx_ref(), a.as_ast()), a.ctx)
4761
4762
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 4763 of file z3py.py.

4763def BVRedOr(a):
4764 """Return the reduction-or expression of `a`."""
4765 if z3_debug():
4766 _z3_assert(is_bv(a), "First argument must be a Z3 bit-vector expression")
4767 return BitVecRef(Z3_mk_bvredor(a.ctx_ref(), a.as_ast()), a.ctx)
4768
4769
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 4837 of file z3py.py.

4837def BVSDivNoOverflow(a, b):
4838 """A predicate the determines that bit-vector signed division does not overflow"""
4839 _check_bv_args(a, b)
4840 a, b = _coerce_exprs(a, b)
4841 return BoolRef(Z3_mk_bvsdiv_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4842
4843
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 4844 of file z3py.py.

4844def BVSNegNoOverflow(a):
4845 """A predicate the determines that bit-vector unary negation does not overflow"""
4846 if z3_debug():
4847 _z3_assert(is_bv(a), "First argument must be a Z3 bit-vector expression")
4848 return BoolRef(Z3_mk_bvneg_no_overflow(a.ctx_ref(), a.as_ast()), a.ctx)
4849
4850
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 4823 of file z3py.py.

4823def BVSubNoOverflow(a, b):
4824 """A predicate the determines that bit-vector subtraction does not overflow"""
4825 _check_bv_args(a, b)
4826 a, b = _coerce_exprs(a, b)
4827 return BoolRef(Z3_mk_bvsub_no_overflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4828
4829
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 4830 of file z3py.py.

4830def BVSubNoUnderflow(a, b, signed):
4831 """A predicate the determines that bit-vector subtraction does not underflow"""
4832 _check_bv_args(a, b)
4833 a, b = _coerce_exprs(a, b)
4834 return BoolRef(Z3_mk_bvsub_no_underflow(a.ctx_ref(), a.as_ast(), b.as_ast(), signed), a.ctx)
4835
4836
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 4796 of file z3py.py.

4796def BvXnor(a, b):
4797 """Return the bitwise XNOR of `a` and `b`.
4798
4799 >>> x = BitVec('x', 8)
4800 >>> y = BitVec('y', 8)
4801 >>> BvXnor(x, y)
4802 bvxnor(x, y)
4803 """
4804 _check_bv_args(a, b)
4805 a, b = _coerce_exprs(a, b)
4806 return BitVecRef(Z3_mk_bvxnor(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4807
4808
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 3707 of file z3py.py.

3707def Cbrt(a, ctx=None):
3708 """ Return a Z3 expression which represents the cubic root of a.
3709
3710 >>> x = Real('x')
3711 >>> Cbrt(x)
3712 x**(1/3)
3713 """
3714 if not is_expr(a):
3715 ctx = _get_ctx(ctx)
3716 a = RealVal(a, ctx)
3717 return a ** "1/3"
3718

◆ CharFromBv()

CharFromBv ( bv)

Definition at line 11860 of file z3py.py.

11860def CharFromBv(bv):
11861 if not is_expr(bv):
11862 raise Z3Exception("Bit-vector expression needed")
11863 return _to_expr_ref(Z3_mk_char_from_bv(bv.ctx_ref(), bv.as_ast()), bv.ctx)
11864
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 11873 of file z3py.py.

11873def CharIsDigit(ch, ctx=None):
11874 ch = _coerce_char(ch, ctx)
11875 return ch.is_digit()
11876

◆ CharSort()

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

Definition at line 11753 of file z3py.py.

11753def CharSort(ctx=None):
11754 """Create a character sort
11755 >>> ch = CharSort()
11756 >>> print(ch)
11757 Char
11758 """
11759 ctx = _get_ctx(ctx)
11760 return CharSortRef(Z3_mk_char_sort(ctx.ref()), ctx)
11761
11762
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 11865 of file z3py.py.

11865def CharToBv(ch, ctx=None):
11866 ch = _coerce_char(ch, ctx)
11867 return ch.to_bv()
11868

◆ CharToInt()

CharToInt ( ch,
ctx = None )

Definition at line 11869 of file z3py.py.

11869def CharToInt(ch, ctx=None):
11870 ch = _coerce_char(ch, ctx)
11871 return ch.to_int()
11872

◆ CharVal()

CharVal ( ch,
ctx = None )

Definition at line 11852 of file z3py.py.

11852def CharVal(ch, ctx=None):
11853 ctx = _get_ctx(ctx)
11854 if isinstance(ch, str):
11855 ch = ord(ch)
11856 if not isinstance(ch, int):
11857 raise Z3Exception("character value should be an ordinal")
11858 return _to_expr_ref(Z3_mk_char(ctx.ref(), ch), ctx)
11859
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 12328 of file z3py.py.

12328def Complement(re):
12329 """Create the complement regular expression."""
12330 return ReRef(Z3_mk_re_complement(re.ctx_ref(), re.as_ast()), re.ctx)
12331
12332
Z3_ast Z3_API Z3_mk_re_complement(Z3_context c, Z3_ast re)
Create the complement of the regular language re.

◆ Complex()

Complex ( name,
ctx = None )
Create a named Complex constant.

Definition at line 3357 of file z3py.py.

3357def Complex(name, ctx=None):
3358 """Create a named Complex constant."""
3359 ctx = _get_ctx(ctx)
3360 return ComplexRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), ComplexSort(ctx).ast), ctx)
3361
3362

Referenced by Complexes().

◆ Complexes()

Complexes ( names,
ctx = None )
Create Complex constants from a space-separated string or list of names.

Definition at line 3363 of file z3py.py.

3363def Complexes(names, ctx=None):
3364 """Create Complex constants from a space-separated string or list of names."""
3365 if isinstance(names, str):
3366 names = names.split(" ")
3367 return [Complex(name, ctx) for name in names]
3368
3369

◆ ComplexSort()

ComplexSort ( ctx = None)
Return the Complex sort in the given context.

Definition at line 3351 of file z3py.py.

3351def ComplexSort(ctx=None):
3352 """Return the Complex sort in the given context."""
3353 ctx = _get_ctx(ctx)
3354 return ComplexSortRef(Z3_mk_complex_sort(ctx.ref()), ctx)
3355
3356
Z3_sort Z3_API Z3_mk_complex_sort(Z3_context c)
Create the Complex sort. Complex numbers are pairs of Reals.

Referenced by Complex().

◆ ComplexVal()

ComplexVal ( real,
imag = 0,
ctx = None )
Construct a Complex value or expression from Int or Real components.

A Python complex value may be passed as the sole component argument.

>>> z = ComplexVal("1/2", 2)
>>> simplify(RealPart(z))
1/2
>>> simplify(ImagPart(z))
2

Definition at line 3370 of file z3py.py.

3370def ComplexVal(real, imag=0, ctx=None):
3371 """Construct a Complex value or expression from Int or Real components.
3372
3373 A Python complex value may be passed as the sole component argument.
3374
3375 >>> z = ComplexVal("1/2", 2)
3376 >>> simplify(RealPart(z))
3377 1/2
3378 >>> simplify(ImagPart(z))
3379 2
3380 """
3381 if isinstance(real, complex):
3382 _z3_assert(imag == 0, "A Python complex value cannot have an additional imaginary component")
3383 real, imag = real.real, real.imag
3384 ctx = _get_ctx(ctx if ctx is not None else _ctx_from_ast_arg_list([real, imag]))
3385 sort = RealSort(ctx)
3386 real, imag = sort.cast(real), sort.cast(imag)
3387 return ComplexRef(Z3_mk_complex(ctx.ref(), real.as_ast(), imag.as_ast()), ctx)
3388
3389
Z3_ast Z3_API Z3_mk_complex(Z3_context c, Z3_ast re, Z3_ast im)
Create a complex number with the given real and imaginary components. Integer components are coerced ...

Referenced by _coerce_expr_list(), _coerce_exprs(), and _py2expr().

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

4370def Concat(*args):
4371 """Create a Z3 bit-vector concatenation expression.
4372
4373 >>> v = BitVecVal(1, 4)
4374 >>> Concat(v, v+1, v)
4375 Concat(Concat(1, 1 + 1), 1)
4376 >>> simplify(Concat(v, v+1, v))
4377 289
4378 >>> print("%.3x" % simplify(Concat(v, v+1, v)).as_long())
4379 121
4380 """
4381 args = _get_args(args)
4382 sz = len(args)
4383 if z3_debug():
4384 _z3_assert(sz >= 2, "At least two arguments expected.")
4385
4386 ctx = None
4387 for a in args:
4388 if is_expr(a):
4389 ctx = a.ctx
4390 break
4391 if is_seq(args[0]) or isinstance(args[0], str):
4392 args = [_coerce_seq(s, ctx) for s in args]
4393 if z3_debug():
4394 _z3_assert(all([is_seq(a) for a in args]), "All arguments must be sequence expressions.")
4395 v = (Ast * sz)()
4396 for i in range(sz):
4397 v[i] = args[i].as_ast()
4398 return SeqRef(Z3_mk_seq_concat(ctx.ref(), sz, v), ctx)
4399
4400 if is_re(args[0]):
4401 if z3_debug():
4402 _z3_assert(all([is_re(a) for a in args]), "All arguments must be regular expressions.")
4403 v = (Ast * sz)()
4404 for i in range(sz):
4405 v[i] = args[i].as_ast()
4406 return ReRef(Z3_mk_re_concat(ctx.ref(), sz, v), ctx)
4407
4408 if z3_debug():
4409 _z3_assert(all([is_bv(a) for a in args]), "All arguments must be Z3 bit-vector expressions.")
4410 r = args[0]
4411 for i in range(sz - 1):
4412 r = BitVecRef(Z3_mk_concat(ctx.ref(), r.as_ast(), args[i + 1].as_ast()), ctx)
4413 return r
4414
4415
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 9710 of file z3py.py.

9710def Cond(p, t1, t2, ctx=None):
9711 """Return a tactic that applies tactic `t1` to a goal if probe `p` evaluates to true, and `t2` otherwise.
9712
9713 >>> t = Cond(Probe('is-qfnra'), Tactic('qfnra'), Tactic('smt'))
9714 """
9715 p = _to_probe(p, ctx)
9716 t1 = _to_tactic(t1, ctx)
9717 t2 = _to_tactic(t2, ctx)
9718 return Tactic(Z3_tactic_cond(t1.ctx.ref(), p.probe, t1.tactic, t2.tactic), t1.ctx)
9719
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 1567 of file z3py.py.

1567def Const(name, sort):
1568 """Create a constant of the given sort.
1569
1570 >>> Const('x', IntSort())
1571 x
1572 """
1573 if z3_debug():
1574 _z3_assert(isinstance(sort, SortRef), "Z3 sort expected")
1575 ctx = sort.ctx
1576 return _to_expr_ref(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), sort.ast), ctx)
1577
1578

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

1579def Consts(names, sort):
1580 """Create several constants of the given sort.
1581
1582 `names` is a string containing the names of all constants to be created.
1583 Blank spaces separate the names of different constants.
1584
1585 >>> x, y, z = Consts('x y z', IntSort())
1586 >>> x + y + z
1587 x + y + z
1588 """
1589 if isinstance(names, str):
1590 names = names.split(" ")
1591 return [Const(name, sort) for name in names]
1592
1593

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

12047def Contains(a, b):
12048 """Check if 'a' contains 'b'
12049 >>> s1 = Contains("abc", "ab")
12050 >>> simplify(s1)
12051 True
12052 >>> s2 = Contains("abc", "bc")
12053 >>> simplify(s2)
12054 True
12055 >>> x, y, z = Strings('x y z')
12056 >>> s3 = Contains(Concat(x,y,z), y)
12057 >>> simplify(s3)
12058 True
12059 """
12060 ctx = _get_ctx2(a, b)
12061 a = _coerce_seq(a, ctx)
12062 b = _coerce_seq(b, ctx)
12063 return BoolRef(Z3_mk_seq_contains(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
12064
12065
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 5771 of file z3py.py.

5771def CreateDatatypes(*ds):
5772 """Create mutually recursive Z3 datatypes using 1 or more Datatype helper objects.
5773
5774 In the following example we define a Tree-List using two mutually recursive datatypes.
5775
5776 >>> TreeList = Datatype('TreeList')
5777 >>> Tree = Datatype('Tree')
5778 >>> # Tree has two constructors: leaf and node
5779 >>> Tree.declare('leaf', ('val', IntSort()))
5780 >>> # a node contains a list of trees
5781 >>> Tree.declare('node', ('children', TreeList))
5782 >>> TreeList.declare('nil')
5783 >>> TreeList.declare('cons', ('car', Tree), ('cdr', TreeList))
5784 >>> Tree, TreeList = CreateDatatypes(Tree, TreeList)
5785 >>> Tree.val(Tree.leaf(10))
5786 val(leaf(10))
5787 >>> simplify(Tree.val(Tree.leaf(10)))
5788 10
5789 >>> n1 = Tree.node(TreeList.cons(Tree.leaf(10), TreeList.cons(Tree.leaf(20), TreeList.nil)))
5790 >>> n1
5791 node(cons(leaf(10), cons(leaf(20), nil)))
5792 >>> n2 = Tree.node(TreeList.cons(n1, TreeList.nil))
5793 >>> simplify(n2 == n1)
5794 False
5795 >>> simplify(TreeList.car(Tree.children(n2)) == n1)
5796 True
5797 """
5798 ds = _get_args(ds)
5799 if z3_debug():
5800 _z3_assert(len(ds) > 0, "At least one Datatype must be specified")
5801 _z3_assert(all([isinstance(d, Datatype) for d in ds]), "Arguments must be Datatypes")
5802 _z3_assert(all([d.ctx == ds[0].ctx for d in ds]), "Context mismatch")
5803 _z3_assert(all([d.constructors != [] for d in ds]), "Non-empty Datatypes expected")
5804 ctx = ds[0].ctx
5805 num = len(ds)
5806 names = (Symbol * num)()
5807 out = (Sort * num)()
5808 clists = (ConstructorList * num)()
5809 to_delete = []
5810 for i in range(num):
5811 d = ds[i]
5812 names[i] = to_symbol(d.name, ctx)
5813 num_cs = len(d.constructors)
5814 cs = (Constructor * num_cs)()
5815 for j in range(num_cs):
5816 c = d.constructors[j]
5817 cname = to_symbol(c[0], ctx)
5818 rname = to_symbol(c[1], ctx)
5819 fs = c[2]
5820 num_fs = len(fs)
5821 fnames = (Symbol * num_fs)()
5822 sorts = (Sort * num_fs)()
5823 refs = (ctypes.c_uint * num_fs)()
5824 for k in range(num_fs):
5825 fname = fs[k][0]
5826 ftype = fs[k][1]
5827 fnames[k] = to_symbol(fname, ctx)
5828 if isinstance(ftype, Datatype):
5829 if z3_debug():
5830 _z3_assert(
5831 ds.count(ftype) == 1,
5832 "One and only one occurrence of each datatype is expected",
5833 )
5834 sorts[k] = None
5835 refs[k] = ds.index(ftype)
5836 else:
5837 if z3_debug():
5838 _z3_assert(is_sort(ftype), "Z3 sort expected")
5839 sorts[k] = ftype.ast
5840 refs[k] = 0
5841 cs[j] = Z3_mk_constructor(ctx.ref(), cname, rname, num_fs, fnames, sorts, refs)
5842 to_delete.append(ScopedConstructor(cs[j], ctx))
5843 clists[i] = Z3_mk_constructor_list(ctx.ref(), num_cs, cs)
5844 to_delete.append(ScopedConstructorList(clists[i], ctx))
5845 Z3_mk_datatypes(ctx.ref(), num, names, out, clists)
5846 result = []
5847 # Create a field for every constructor, recognizer and accessor
5848 for i in range(num):
5849 dref = DatatypeSortRef(out[i], ctx)
5850 num_cs = dref.num_constructors()
5851 for j in range(num_cs):
5852 cref = dref.constructor(j)
5853 cref_name = cref.name()
5854 cref_arity = cref.arity()
5855 if cref.arity() == 0:
5856 cref = cref()
5857 setattr(dref, cref_name, cref)
5858 rref = dref.recognizer(j)
5859 setattr(dref, "is_" + cref_name, rref)
5860 for k in range(cref_arity):
5861 aref = dref.accessor(j, k)
5862 setattr(dref, aref.name(), aref)
5863 result.append(dref)
5864 return tuple(result)
5865
5866
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 5867 of file z3py.py.

5867def CreatePolymorphicDatatype(d, type_params):
5868 """Create a single polymorphic Z3 datatype with explicit type parameters.
5869
5870 `d` is a `Datatype` helper object whose constructors have been declared.
5871 `type_params` is a list of type variables created with `DeclareTypeVar`.
5872 Constructor field sorts may reference these type variables, and self-recursive
5873 fields may reference `d` directly.
5874
5875 >>> A = DeclareTypeVar('A')
5876 >>> Pair = Datatype('Pair')
5877 >>> Pair.declare('pair', ('fst', A), ('snd', A))
5878 >>> Pair = CreatePolymorphicDatatype(Pair, [A])
5879 """
5880 if z3_debug():
5881 _z3_assert(isinstance(d, Datatype), "Datatype expected")
5882 _z3_assert(d.constructors != [], "Non-empty Datatype expected")
5883 ctx = d.ctx
5884 name = to_symbol(d.name, ctx)
5885 num_params = len(type_params)
5886 params_arr = (Sort * num_params)()
5887 for i, p in enumerate(type_params):
5888 if z3_debug():
5889 _z3_assert(is_sort(p), "Z3 sort expected for type parameter")
5890 params_arr[i] = p.ast
5891 num_cs = len(d.constructors)
5892 cs = (Constructor * num_cs)()
5893 to_delete = []
5894 for j in range(num_cs):
5895 c = d.constructors[j]
5896 cname = to_symbol(c[0], ctx)
5897 rname = to_symbol(c[1], ctx)
5898 fs = c[2]
5899 num_fs = len(fs)
5900 fnames = (Symbol * num_fs)()
5901 sorts = (Sort * num_fs)()
5902 refs = (ctypes.c_uint * num_fs)()
5903 for k in range(num_fs):
5904 fname = fs[k][0]
5905 ftype = fs[k][1]
5906 fnames[k] = to_symbol(fname, ctx)
5907 if isinstance(ftype, Datatype):
5908 if z3_debug():
5909 _z3_assert(ftype is d, "Only self-recursive references are supported in polymorphic datatypes. Use CreateDatatypes for mutually recursive datatypes.")
5910 sorts[k] = None
5911 refs[k] = 0
5912 else:
5913 if z3_debug():
5914 _z3_assert(is_sort(ftype), "Z3 sort expected")
5915 sorts[k] = ftype.ast
5916 refs[k] = 0
5917 cs[j] = Z3_mk_constructor(ctx.ref(), cname, rname, num_fs, fnames, sorts, refs)
5918 to_delete.append(ScopedConstructor(cs[j], ctx))
5919 out = Z3_mk_polymorphic_datatype(ctx.ref(), name, num_params, params_arr, num_cs, cs)
5920 dref = DatatypeSortRef(out, ctx)
5921 num_cs_actual = dref.num_constructors()
5922 for j in range(num_cs_actual):
5923 cref = dref.constructor(j)
5924 cref_name = cref.name()
5925 cref_arity = cref.arity()
5926 if cref_arity == 0:
5927 cref = cref()
5928 setattr(dref, cref_name, cref)
5929 rref = dref.recognizer(j)
5930 setattr(dref, "is_" + cref_name, rref)
5931 for k in range(cref_arity):
5932 aref = dref.accessor(j, k)
5933 setattr(dref, aref.name(), aref)
5934 return dref
5935
5936
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 6067 of file z3py.py.

6067def DatatypeSort(name, params=None, ctx=None):
6068 """Create a reference to a sort that was declared, or will be declared, as a recursive datatype.
6069
6070 Args:
6071 name: name of the datatype sort
6072 params: optional list/tuple of sort parameters for parametric datatypes
6073 ctx: Z3 context (optional)
6074
6075 Example:
6076 >>> # Non-parametric datatype
6077 >>> TreeRef = DatatypeSort('Tree')
6078 >>> # Parametric datatype with one parameter
6079 >>> ListIntRef = DatatypeSort('List', [IntSort()])
6080 >>> # Parametric datatype with multiple parameters
6081 >>> PairRef = DatatypeSort('Pair', [IntSort(), BoolSort()])
6082 """
6083 ctx = _get_ctx(ctx)
6084 if params is None or len(params) == 0:
6085 return DatatypeSortRef(Z3_mk_datatype_sort(ctx.ref(), to_symbol(name, ctx), 0, (Sort * 0)()), ctx)
6086 else:
6087 _params = (Sort * len(params))()
6088 for i in range(len(params)):
6089 _params[i] = params[i].ast
6090 return DatatypeSortRef(Z3_mk_datatype_sort(ctx.ref(), to_symbol(name, ctx), len(params), _params), ctx)
6091
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 737 of file z3py.py.

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

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

5131def Default(a):
5132 """ Return a default value for array expression.
5133 >>> b = K(IntSort(), 1)
5134 >>> prove(Default(b) == 1)
5135 proved
5136 """
5137 if z3_debug():
5138 _z3_assert(is_array_sort(a), "First argument must be a Z3 array expression")
5139 return a.default()
5140
5141

◆ describe_probes()

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

Definition at line 9631 of file z3py.py.

9631def describe_probes():
9632 """Display a (tabular) description of all available probes in Z3."""
9633 if in_html_mode():
9634 even = True
9635 print('<table border="1" cellpadding="2" cellspacing="0">')
9636 for p in probes():
9637 if even:
9638 print('<tr style="background-color:#CFCFCF">')
9639 even = False
9640 else:
9641 print("<tr>")
9642 even = True
9643 print("<td>%s</td><td>%s</td></tr>" % (p, insert_line_breaks(probe_description(p), 40)))
9644 print("</table>")
9645 else:
9646 for p in probes():
9647 print("%s : %s" % (p, probe_description(p)))
9648
9649

◆ describe_tactics()

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

Definition at line 9425 of file z3py.py.

9425def describe_tactics():
9426 """Display a (tabular) description of all available tactics in Z3."""
9427 if in_html_mode():
9428 even = True
9429 print('<table border="1" cellpadding="2" cellspacing="0">')
9430 for t in tactics():
9431 if even:
9432 print('<tr style="background-color:#CFCFCF">')
9433 even = False
9434 else:
9435 print("<tr>")
9436 even = True
9437 print("<td>%s</td><td>%s</td></tr>" % (t, insert_line_breaks(tactic_description(t), 40)))
9438 print("</table>")
9439 else:
9440 for t in tactics():
9441 print("%s : %s" % (t, tactic_description(t)))
9442
9443

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

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

◆ Diff()

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

Definition at line 12378 of file z3py.py.

12378def Diff(a, b, ctx=None):
12379 """Create the difference regular expression
12380 """
12381 if z3_debug():
12382 _z3_assert(is_expr(a), "expression expected")
12383 _z3_assert(is_expr(b), "expression expected")
12384 return ReRef(Z3_mk_re_diff(a.ctx_ref(), a.ast, b.ast), a.ctx)
12385
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 6104 of file z3py.py.

6104def DisjointSum(name, sorts, ctx=None):
6105 """Create a named tagged union sort base on a set of underlying sorts
6106 Example:
6107 >>> sum, ((inject0, extract0), (inject1, extract1)) = DisjointSum("+", [IntSort(), StringSort()])
6108 """
6109 sum = Datatype(name, ctx)
6110 for i in range(len(sorts)):
6111 sum.declare("inject%d" % i, ("project%d" % i, sorts[i]))
6112 sum = sum.create()
6113 return sum, [(sum.constructor(i), sum.accessor(i, 0)) for i in range(len(sorts))]
6114
6115

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

1534def Distinct(*args):
1535 """Create a Z3 distinct expression.
1536
1537 >>> x = Int('x')
1538 >>> y = Int('y')
1539 >>> Distinct(x, y)
1540 x != y
1541 >>> z = Int('z')
1542 >>> Distinct(x, y, z)
1543 Distinct(x, y, z)
1544 >>> simplify(Distinct(x, y, z))
1545 Distinct(x, y, z)
1546 >>> simplify(Distinct(x, y, z), blast_distinct=True)
1547 And(Not(x == y), Not(x == z), Not(y == z))
1548 """
1549 args = _get_args(args)
1550 ctx = _ctx_from_ast_arg_list(args)
1551 if z3_debug():
1552 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
1553 args = _coerce_expr_list(args, ctx)
1554 _args, sz = _to_ast_array(args)
1555 return BoolRef(Z3_mk_distinct(ctx.ref(), sz, _args), ctx)
1556
1557
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 11977 of file z3py.py.

11977def Empty(s):
11978 """Create the empty sequence of the given sort
11979 >>> e = Empty(StringSort())
11980 >>> e2 = StringVal("")
11981 >>> print(e.eq(e2))
11982 True
11983 >>> e3 = Empty(SeqSort(IntSort()))
11984 >>> print(e3)
11985 Empty(Seq(Int))
11986 >>> e4 = Empty(ReSort(SeqSort(IntSort())))
11987 >>> print(e4)
11988 Empty(ReSort(Seq(Int)))
11989 """
11990 if isinstance(s, SeqSortRef):
11991 return SeqRef(Z3_mk_seq_empty(s.ctx_ref(), s.ast), s.ctx)
11992 if isinstance(s, ReSortRef):
11993 return ReRef(Z3_mk_re_empty(s.ctx_ref(), s.ast), s.ctx)
11994 raise Z3Exception("Non-sequence, non-regular expression sort passed to Empty")
11995
11996
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 5286 of file z3py.py.

5286def EmptySet(s):
5287 """Create the empty set
5288 >>> EmptySet(IntSort())
5289 K(Int, False)
5290 """
5291 ctx = s.ctx
5292 if is_finite_set_sort(s):
5293 return FiniteSetEmpty(s)
5294 return ArrayRef(Z3_mk_empty_set(ctx.ref(), s.ast), ctx)
5295
5296
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 12497 of file z3py.py.

12497def ensure_prop_closures():
12498 global _prop_closures
12499 if _prop_closures is None:
12500 _prop_closures = PropClosures()
12501
12502

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

6116def EnumSort(name, values, ctx=None):
6117 """Return a new enumeration sort named `name` containing the given values.
6118
6119 The result is a pair (sort, list of constants).
6120 Example:
6121 >>> Color, (red, green, blue) = EnumSort('Color', ['red', 'green', 'blue'])
6122 """
6123 if z3_debug():
6124 _z3_assert(isinstance(name, str), "Name must be a string")
6125 _z3_assert(all([isinstance(v, str) for v in values]), "Enumeration sort values must be strings")
6126 _z3_assert(len(values) > 0, "At least one value expected")
6127 ctx = _get_ctx(ctx)
6128 num = len(values)
6129 _val_names = (Symbol * num)()
6130 for i in range(num):
6131 _val_names[i] = to_symbol(values[i], ctx)
6132 _values = (FuncDecl * num)()
6133 _testers = (FuncDecl * num)()
6134 name = to_symbol(name, ctx)
6135 S = DatatypeSortRef(Z3_mk_enumeration_sort(ctx.ref(), name, num, _val_names, _values, _testers), ctx)
6136 V = []
6137 for i in range(num):
6138 V.append(FuncDeclRef(_values[i], ctx))
6139 V = [a() for a in V]
6140 return S, V
6141
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 2411 of file z3py.py.

2411def Exists(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2412 """Create a Z3 exists formula.
2413
2414 The parameters `weight`, `qif`, `skid`, `patterns` and `no_patterns` are optional annotations.
2415
2416
2417 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2418 >>> x = Int('x')
2419 >>> y = Int('y')
2420 >>> q = Exists([x, y], f(x, y) >= x, skid="foo")
2421 >>> q
2422 Exists([x, y], f(x, y) >= x)
2423 >>> is_quantifier(q)
2424 True
2425 >>> r = Tactic('nnf')(q).as_expr()
2426 >>> is_quantifier(r)
2427 False
2428 """
2429 return _mk_quantifier(False, vs, body, weight, qid, skid, patterns, no_patterns)
2430
2431

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

5220def Ext(a, b):
5221 """Return extensionality index for one-dimensional arrays.
5222 >> a, b = Consts('a b', SetSort(IntSort()))
5223 >> Ext(a, b)
5224 Ext(a, b)
5225 """
5226 ctx = a.ctx
5227 if z3_debug():
5228 _z3_assert(is_array_sort(a) and (is_array(b) or b.is_lambda()), "arguments must be arrays")
5229 return _to_expr_ref(Z3_mk_array_ext(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
5230
5231
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 4416 of file z3py.py.

4416def Extract(high, low, a):
4417 """Create a Z3 bit-vector extraction expression or sequence extraction expression.
4418
4419 Extract is overloaded to work with both bit-vectors and sequences:
4420
4421 **Bit-vector extraction**: Extract(high, low, bitvector)
4422 Extracts bits from position `high` down to position `low` (both inclusive).
4423 - high: int - the highest bit position to extract (0-indexed from right)
4424 - low: int - the lowest bit position to extract (0-indexed from right)
4425 - bitvector: BitVecRef - the bit-vector to extract from
4426 Returns a new bit-vector containing bits [high:low]
4427
4428 **Sequence extraction**: Extract(sequence, offset, length)
4429 Extracts a subsequence starting at the given offset with the specified length.
4430 The functions SubString and SubSeq are redirected to this form of Extract.
4431 - sequence: SeqRef or str - the sequence to extract from
4432 - offset: int - the starting position (0-indexed)
4433 - length: int - the number of elements to extract
4434 Returns a new sequence containing the extracted subsequence
4435
4436 >>> # Bit-vector extraction examples
4437 >>> x = BitVec('x', 8)
4438 >>> Extract(6, 2, x) # Extract bits 6 down to 2 (5 bits total)
4439 Extract(6, 2, x)
4440 >>> Extract(6, 2, x).sort() # Result is a 5-bit vector
4441 BitVec(5)
4442 >>> Extract(7, 0, x) # Extract all 8 bits
4443 Extract(7, 0, x)
4444 >>> Extract(3, 3, x) # Extract single bit at position 3
4445 Extract(3, 3, x)
4446
4447 >>> # Sequence extraction examples
4448 >>> s = StringVal("hello")
4449 >>> Extract(s, 1, 3) # Extract 3 characters starting at position 1
4450 str.substr("hello", 1, 3)
4451 >>> simplify(Extract(StringVal("abcd"), 2, 1)) # Extract 1 character at position 2
4452 "c"
4453 >>> simplify(Extract(StringVal("abcd"), 0, 2)) # Extract first 2 characters
4454 "ab"
4455 """
4456 if isinstance(high, str):
4457 high = StringVal(high)
4458 if is_seq(high):
4459 s = high
4460 offset, length = _coerce_exprs(low, a, s.ctx)
4461 return SeqRef(Z3_mk_seq_extract(s.ctx_ref(), s.as_ast(), offset.as_ast(), length.as_ast()), s.ctx)
4462 if z3_debug():
4463 _z3_assert(low <= high, "First argument must be greater than or equal to second argument")
4464 _z3_assert(_is_int(high) and high >= 0 and _is_int(low) and low >= 0,
4465 "First and second arguments must be non negative integers")
4466 _z3_assert(is_bv(a), "Third argument must be a Z3 bit-vector expression")
4467 return BitVecRef(Z3_mk_extract(a.ctx_ref(), high, low, a.as_ast()), a.ctx)
4468
4469
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 9668 of file z3py.py.

9668def FailIf(p, ctx=None):
9669 """Return a tactic that fails if the probe `p` evaluates to true.
9670 Otherwise, it returns the input goal unmodified.
9671
9672 In the following example, the tactic applies 'simplify' if and only if there are
9673 more than 2 constraints in the goal.
9674
9675 >>> t = OrElse(FailIf(Probe('size') > 2), Tactic('simplify'))
9676 >>> x, y = Ints('x y')
9677 >>> g = Goal()
9678 >>> g.add(x > 0)
9679 >>> g.add(y > 0)
9680 >>> t(g)
9681 [[x > 0, y > 0]]
9682 >>> g.add(x == y + 1)
9683 >>> t(g)
9684 [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
9685 """
9686 p = _to_probe(p, ctx)
9687 return Tactic(Z3_tactic_fail_if(p.ctx.ref(), p.probe), p.ctx)
9688
9689
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 8566 of file z3py.py.

8566def FiniteDomainSort(name, sz, ctx=None):
8567 """Create a named finite domain sort of a given size sz"""
8568 if not isinstance(name, Symbol):
8569 name = to_symbol(name)
8570 ctx = _get_ctx(ctx)
8571 return FiniteDomainSortRef(Z3_mk_finite_domain_sort(ctx.ref(), name, sz), ctx)
8572
8573
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 8636 of file z3py.py.

8636def FiniteDomainVal(val, sort, ctx=None):
8637 """Return a Z3 finite-domain value. If `ctx=None`, then the global context is used.
8638
8639 >>> s = FiniteDomainSort('S', 256)
8640 >>> FiniteDomainVal(255, s)
8641 255
8642 >>> FiniteDomainVal('100', s)
8643 100
8644 """
8645 if z3_debug():
8646 _z3_assert(is_finite_domain_sort(sort), "Expected finite-domain sort")
8647 ctx = sort.ctx
8648 return FiniteDomainNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), sort.ast), ctx)
8649
8650

◆ FiniteFieldBitsum()

FiniteFieldBitsum ( * args)

Definition at line 12862 of file z3py.py.

12862def FiniteFieldBitsum(*args):
12863 args = _get_args(args)
12864 if len(args) < 2 or not isinstance(args[0], FiniteFieldRef):
12865 raise Z3Exception("bitsum needs at least two field arguments")
12866 field = args[0].sort()
12867 values = [field.cast(a) for a in args]
12868 raw = (Ast * len(values))(*[a.as_ast() for a in values])
12869 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 12850 of file z3py.py.

12850def FiniteFieldElem(name, field, ctx=None):
12851 if not isinstance(field, FiniteFieldSortRef):
12852 field = FiniteFieldSort(field, ctx)
12853 return Const(name, field)
12854
12855

◆ FiniteFieldElems()

FiniteFieldElems ( names,
field,
ctx = None )

Definition at line 12856 of file z3py.py.

12856def FiniteFieldElems(names, field, ctx=None):
12857 if not isinstance(field, FiniteFieldSortRef):
12858 field = FiniteFieldSort(field, ctx)
12859 return [Const(name, field) for name in (names.split() if isinstance(names, str) else names)]
12860
12861

◆ FiniteFieldSort()

FiniteFieldSort ( prime,
ctx = None )

Definition at line 12837 of file z3py.py.

12837def FiniteFieldSort(prime, ctx=None):
12838 ctx = _get_ctx(ctx)
12839 return FiniteFieldSortRef(Z3_mk_finite_field_sort(ctx.ref(), str(prime)), ctx)
12840
12841
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 12842 of file z3py.py.

12842def FiniteFieldVal(value, field, ctx=None):
12843 if not isinstance(field, FiniteFieldSortRef):
12844 field = FiniteFieldSort(field, ctx)
12845 if not isinstance(value, (int, str)):
12846 raise Z3Exception("finite-field value must be an integer")
12847 return FiniteFieldRef(Z3_mk_numeral(field.ctx_ref(), str(value), field.ast), field.ctx)
12848
12849

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

5551def FiniteSetDifference(s1, s2):
5552 """Create the set difference of two finite sets.
5553 >>> a = Const('a', FiniteSetSort(IntSort()))
5554 >>> b = Const('b', FiniteSetSort(IntSort()))
5555 >>> FiniteSetDifference(a, b)
5556 set.difference(a, b)
5557 """
5558 ctx = _ctx_from_ast_arg_list([s1, s2])
5559 return FiniteSetRef(Z3_mk_finite_set_difference(ctx.ref(), s1.as_ast(), s2.as_ast()), ctx)
5560
5561
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 5510 of file z3py.py.

5510def FiniteSetEmpty(set_sort):
5511 """Create an empty finite set of the given sort.
5512 >>> s = FiniteSetSort(IntSort())
5513 >>> FiniteSetEmpty(s)
5514 set.empty
5515 """
5516 ctx = set_sort.ctx
5517 return FiniteSetRef(Z3_mk_finite_set_empty(ctx.ref(), set_sort.ast), ctx)
5518
5519
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 5608 of file z3py.py.

5608def FiniteSetFilter(f, set):
5609 """Filter a finite set using predicate f.
5610 >>> f = Array('f', IntSort(), BoolSort())
5611 >>> a = Const('a', FiniteSetSort(IntSort()))
5612 >>> FiniteSetFilter(f, a)
5613 set.filter(f, a)
5614 """
5615 if isinstance(f, FuncDeclRef):
5616 f = AsArray(f)
5617 ctx = _ctx_from_ast_arg_list([f, set])
5618 return FiniteSetRef(Z3_mk_finite_set_filter(ctx.ref(), f.as_ast(), set.as_ast()), ctx)
5619
5620
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 5540 of file z3py.py.

5540def FiniteSetIntersect(s1, s2):
5541 """Create the intersection of two finite sets.
5542 >>> a = Const('a', FiniteSetSort(IntSort()))
5543 >>> b = Const('b', FiniteSetSort(IntSort()))
5544 >>> FiniteSetIntersect(a, b)
5545 set.intersect(a, b)
5546 """
5547 ctx = _ctx_from_ast_arg_list([s1, s2])
5548 return FiniteSetRef(Z3_mk_finite_set_intersect(ctx.ref(), s1.as_ast(), s2.as_ast()), ctx)
5549
5550
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 5595 of file z3py.py.

5595def FiniteSetMap(f, set):
5596 """Apply function f to all elements of the finite set.
5597 >>> f = Array('f', IntSort(), IntSort())
5598 >>> a = Const('a', FiniteSetSort(IntSort()))
5599 >>> FiniteSetMap(f, a)
5600 set.map(f, a)
5601 """
5602 if isinstance(f, FuncDeclRef):
5603 f = AsArray(f)
5604 ctx = _ctx_from_ast_arg_list([f, set])
5605 return FiniteSetRef(Z3_mk_finite_set_map(ctx.ref(), f.as_ast(), set.as_ast()), ctx)
5606
5607
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 5562 of file z3py.py.

5562def FiniteSetMember(elem, set):
5563 """Check if elem is a member of the finite set.
5564 >>> a = Const('a', FiniteSetSort(IntSort()))
5565 >>> FiniteSetMember(IntVal(1), a)
5566 set.in(1, a)
5567 """
5568 ctx = _ctx_from_ast_arg_list([elem, set])
5569 return BoolRef(Z3_mk_finite_set_member(ctx.ref(), elem.as_ast(), set.as_ast()), ctx)
5570
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 5621 of file z3py.py.

5621def FiniteSetRange(low, high):
5622 """Create a finite set of integers in the range [low, high).
5623 >>> FiniteSetRange(IntVal(0), IntVal(5))
5624 set.range(0, 5)
5625 """
5626 ctx = _ctx_from_ast_arg_list([low, high])
5627 return FiniteSetRef(Z3_mk_finite_set_range(ctx.ref(), low.as_ast(), high.as_ast()), ctx)
5628
5629
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 5574 of file z3py.py.

5574def FiniteSetSize(set):
5575 """Get the size (cardinality) of a finite set.
5576 >>> a = Const('a', FiniteSetSort(IntSort()))
5577 >>> FiniteSetSize(a)
5578 set.size(a)
5579 """
5580 ctx = set.ctx
5581 return ArithRef(Z3_mk_finite_set_size(ctx.ref(), set.as_ast()), ctx)
5582
5583
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 5501 of file z3py.py.

5501def FiniteSetSort(elem_sort):
5502 """Create a finite set sort over element sort elem_sort.
5503 >>> s = FiniteSetSort(IntSort())
5504 >>> s
5505 FiniteSet(Int)
5506 """
5507 return FiniteSetSortRef(Z3_mk_finite_set_sort(elem_sort.ctx_ref(), elem_sort.ast), elem_sort.ctx)
5508
5509
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 5584 of file z3py.py.

5584def FiniteSetSubset(s1, s2):
5585 """Check if s1 is a subset of s2.
5586 >>> a = Const('a', FiniteSetSort(IntSort()))
5587 >>> b = Const('b', FiniteSetSort(IntSort()))
5588 >>> FiniteSetSubset(a, b)
5589 set.subset(a, b)
5590 """
5591 ctx = _ctx_from_ast_arg_list([s1, s2])
5592 return BoolRef(Z3_mk_finite_set_subset(ctx.ref(), s1.as_ast(), s2.as_ast()), ctx)
5593
5594
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 5529 of file z3py.py.

5529def FiniteSetUnion(s1, s2):
5530 """Create the union of two finite sets.
5531 >>> a = Const('a', FiniteSetSort(IntSort()))
5532 >>> b = Const('b', FiniteSetSort(IntSort()))
5533 >>> FiniteSetUnion(a, b)
5534 set.union(a, b)
5535 """
5536 ctx = _ctx_from_ast_arg_list([s1, s2])
5537 return FiniteSetRef(Z3_mk_finite_set_union(ctx.ref(), s1.as_ast(), s2.as_ast()), ctx)
5538
5539
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 10396 of file z3py.py.

10396def Float128(ctx=None):
10397 """Floating-point 128-bit (quadruple) sort."""
10398 ctx = _get_ctx(ctx)
10399 return FPSortRef(Z3_mk_fpa_sort_128(ctx.ref()), ctx)
10400
10401
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 10360 of file z3py.py.

10360def Float16(ctx=None):
10361 """Floating-point 16-bit (half) sort."""
10362 ctx = _get_ctx(ctx)
10363 return FPSortRef(Z3_mk_fpa_sort_16(ctx.ref()), ctx)
10364
10365
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 10372 of file z3py.py.

10372def Float32(ctx=None):
10373 """Floating-point 32-bit (single) sort."""
10374 ctx = _get_ctx(ctx)
10375 return FPSortRef(Z3_mk_fpa_sort_32(ctx.ref()), ctx)
10376
10377
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 10384 of file z3py.py.

10384def Float64(ctx=None):
10385 """Floating-point 64-bit (double) sort."""
10386 ctx = _get_ctx(ctx)
10387 return FPSortRef(Z3_mk_fpa_sort_64(ctx.ref()), ctx)
10388
10389
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 10390 of file z3py.py.

10390def FloatDouble(ctx=None):
10391 """Floating-point 64-bit (double) sort."""
10392 ctx = _get_ctx(ctx)
10393 return FPSortRef(Z3_mk_fpa_sort_double(ctx.ref()), ctx)
10394
10395
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 10366 of file z3py.py.

10366def FloatHalf(ctx=None):
10367 """Floating-point 16-bit (half) sort."""
10368 ctx = _get_ctx(ctx)
10369 return FPSortRef(Z3_mk_fpa_sort_half(ctx.ref()), ctx)
10370
10371
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 10402 of file z3py.py.

10402def FloatQuadruple(ctx=None):
10403 """Floating-point 128-bit (quadruple) sort."""
10404 ctx = _get_ctx(ctx)
10405 return FPSortRef(Z3_mk_fpa_sort_quadruple(ctx.ref()), ctx)
10406
10407
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 10378 of file z3py.py.

10378def FloatSingle(ctx=None):
10379 """Floating-point 32-bit (single) sort."""
10380 ctx = _get_ctx(ctx)
10381 return FPSortRef(Z3_mk_fpa_sort_single(ctx.ref()), ctx)
10382
10383
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 2393 of file z3py.py.

2393def ForAll(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2394 """Create a Z3 forall formula.
2395
2396 The parameters `weight`, `qid`, `skid`, `patterns` and `no_patterns` are optional annotations.
2397
2398 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2399 >>> x = Int('x')
2400 >>> y = Int('y')
2401 >>> ForAll([x, y], f(x, y) >= x)
2402 ForAll([x, y], f(x, y) >= x)
2403 >>> ForAll([x, y], f(x, y) >= x, patterns=[ f(x, y) ])
2404 ForAll([x, y], f(x, y) >= x)
2405 >>> ForAll([x, y], f(x, y) >= x, weight=10)
2406 ForAll([x, y], f(x, y) >= x)
2407 """
2408 return _mk_quantifier(True, vs, body, weight, qid, skid, patterns, no_patterns)
2409
2410

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

11070def FP(name, fpsort, ctx=None):
11071 """Return a floating-point constant named `name`.
11072 `fpsort` is the floating-point sort.
11073 If `ctx=None`, then the global context is used.
11074
11075 >>> x = FP('x', FPSort(8, 24))
11076 >>> is_fp(x)
11077 True
11078 >>> x.ebits()
11079 8
11080 >>> x.sort()
11081 FPSort(8, 24)
11082 >>> word = FPSort(8, 24)
11083 >>> x2 = FP('x', word)
11084 >>> eq(x, x2)
11085 True
11086 """
11087 if isinstance(fpsort, FPSortRef) and ctx is None:
11088 ctx = fpsort.ctx
11089 else:
11090 ctx = _get_ctx(ctx)
11091 return FPRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), fpsort.ast), ctx)
11092
11093

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

11113def fpAbs(a, ctx=None):
11114 """Create a Z3 floating-point absolute value expression.
11115
11116 >>> s = FPSort(8, 24)
11117 >>> rm = RNE()
11118 >>> x = FPVal(1.0, s)
11119 >>> fpAbs(x)
11120 fpAbs(1)
11121 >>> y = FPVal(-20.0, s)
11122 >>> y
11123 -1.25*(2**4)
11124 >>> fpAbs(y)
11125 fpAbs(-1.25*(2**4))
11126 >>> fpAbs(-1.25*(2**4))
11127 fpAbs(-1.25*(2**4))
11128 >>> fpAbs(x).sort()
11129 FPSort(8, 24)
11130 """
11131 ctx = _get_ctx(ctx)
11132 [a] = _coerce_fp_expr_list([a], ctx)
11133 return FPRef(Z3_mk_fpa_abs(ctx.ref(), a.as_ast()), ctx)
11134
11135
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 11204 of file z3py.py.

11204def fpAdd(rm, a, b, ctx=None):
11205 """Create a Z3 floating-point addition expression.
11206
11207 >>> s = FPSort(8, 24)
11208 >>> rm = RNE()
11209 >>> x = FP('x', s)
11210 >>> y = FP('y', s)
11211 >>> fpAdd(rm, x, y)
11212 x + y
11213 >>> fpAdd(RTZ(), x, y) # default rounding mode is RTZ
11214 fpAdd(RTZ(), x, y)
11215 >>> fpAdd(rm, x, y).sort()
11216 FPSort(8, 24)
11217 """
11218 return _mk_fp_bin(Z3_mk_fpa_add, rm, a, b, ctx)
11219
11220

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

11526def fpBVToFP(v, sort, ctx=None):
11527 """Create a Z3 floating-point conversion expression that represents the
11528 conversion from a bit-vector term to a floating-point term.
11529
11530 >>> x_bv = BitVecVal(0x3F800000, 32)
11531 >>> x_fp = fpBVToFP(x_bv, Float32())
11532 >>> x_fp
11533 fpToFP(1065353216)
11534 >>> simplify(x_fp)
11535 1
11536 """
11537 _z3_assert(is_bv(v), "First argument must be a Z3 bit-vector expression")
11538 _z3_assert(is_fp_sort(sort), "Second argument must be a Z3 floating-point sort.")
11539 ctx = _get_ctx(ctx)
11540 return FPRef(Z3_mk_fpa_to_fp_bv(ctx.ref(), v.ast, sort.ast), ctx)
11541
11542
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 11251 of file z3py.py.

11251def fpDiv(rm, a, b, ctx=None):
11252 """Create a Z3 floating-point division expression.
11253
11254 >>> s = FPSort(8, 24)
11255 >>> rm = RNE()
11256 >>> x = FP('x', s)
11257 >>> y = FP('y', s)
11258 >>> fpDiv(rm, x, y)
11259 x / y
11260 >>> fpDiv(rm, x, y).sort()
11261 FPSort(8, 24)
11262 """
11263 return _mk_fp_bin(Z3_mk_fpa_div, rm, a, b, ctx)
11264
11265

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

11434def fpEQ(a, b, ctx=None):
11435 """Create the Z3 floating-point expression `fpEQ(other, self)`.
11436
11437 >>> x, y = FPs('x y', FPSort(8, 24))
11438 >>> fpEQ(x, y)
11439 fpEQ(x, y)
11440 >>> fpEQ(x, y).sexpr()
11441 '(fp.eq x y)'
11442 """
11443 return _mk_fp_bin_pred(Z3_mk_fpa_eq, a, b, ctx)
11444
11445

◆ fpFMA()

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

Definition at line 11310 of file z3py.py.

11310def fpFMA(rm, a, b, c, ctx=None):
11311 """Create a Z3 floating-point fused multiply-add expression.
11312 """
11313 return _mk_fp_tern(Z3_mk_fpa_fma, rm, a, b, c, ctx)
11314
11315

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

11458def fpFP(sgn, exp, sig, ctx=None):
11459 """Create the Z3 floating-point value `fpFP(sgn, sig, exp)` from the three bit-vectors sgn, sig, and exp.
11460
11461 >>> s = FPSort(8, 24)
11462 >>> x = fpFP(BitVecVal(1, 1), BitVecVal(2**7-1, 8), BitVecVal(2**22, 23))
11463 >>> print(x)
11464 fpFP(1, 127, 4194304)
11465 >>> xv = FPVal(-1.5, s)
11466 >>> print(xv)
11467 -1.5
11468 >>> slvr = Solver()
11469 >>> slvr.add(fpEQ(x, xv))
11470 >>> slvr.check()
11471 sat
11472 >>> xv = FPVal(+1.5, s)
11473 >>> print(xv)
11474 1.5
11475 >>> slvr = Solver()
11476 >>> slvr.add(fpEQ(x, xv))
11477 >>> slvr.check()
11478 unsat
11479 """
11480 _z3_assert(is_bv(sgn) and is_bv(exp) and is_bv(sig), "sort mismatch")
11481 _z3_assert(sgn.sort().size() == 1, "sort mismatch")
11482 ctx = _get_ctx(ctx)
11483 _z3_assert(ctx == sgn.ctx == exp.ctx == sig.ctx, "context mismatch")
11484 return FPRef(Z3_mk_fpa_fp(ctx.ref(), sgn.ast, exp.ast, sig.ast), ctx)
11485
11486

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

11543def fpFPToFP(rm, v, sort, ctx=None):
11544 """Create a Z3 floating-point conversion expression that represents the
11545 conversion from a floating-point term to a floating-point term of different precision.
11546
11547 >>> x_sgl = FPVal(1.0, Float32())
11548 >>> x_dbl = fpFPToFP(RNE(), x_sgl, Float64())
11549 >>> x_dbl
11550 fpToFP(RNE(), 1)
11551 >>> simplify(x_dbl)
11552 1
11553 >>> x_dbl.sort()
11554 FPSort(11, 53)
11555 """
11556 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
11557 _z3_assert(is_fp(v), "Second argument must be a Z3 floating-point expression.")
11558 _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
11559 ctx = _get_ctx(ctx)
11560 return FPRef(Z3_mk_fpa_to_fp_float(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
11561
11562
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 11422 of file z3py.py.

11422def fpGEQ(a, b, ctx=None):
11423 """Create the Z3 floating-point expression `other >= self`.
11424
11425 >>> x, y = FPs('x y', FPSort(8, 24))
11426 >>> fpGEQ(x, y)
11427 x >= y
11428 >>> (x >= y).sexpr()
11429 '(fp.geq x y)'
11430 """
11431 return _mk_fp_bin_pred(Z3_mk_fpa_geq, a, b, ctx)
11432
11433

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

11410def fpGT(a, b, ctx=None):
11411 """Create the Z3 floating-point expression `other > self`.
11412
11413 >>> x, y = FPs('x y', FPSort(8, 24))
11414 >>> fpGT(x, y)
11415 x > y
11416 >>> (x > y).sexpr()
11417 '(fp.gt x y)'
11418 """
11419 return _mk_fp_bin_pred(Z3_mk_fpa_gt, a, b, ctx)
11420
11421

◆ fpInfinity()

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

Definition at line 10971 of file z3py.py.

10971def fpInfinity(s, negative):
10972 """Create a Z3 floating-point +oo or -oo term."""
10973 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10974 _z3_assert(isinstance(negative, bool), "expected Boolean flag")
10975 return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, negative), s.ctx)
10976
10977
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 11340 of file z3py.py.

11340def fpIsInf(a, ctx=None):
11341 """Create a Z3 floating-point isInfinite expression.
11342
11343 >>> s = FPSort(8, 24)
11344 >>> x = FP('x', s)
11345 >>> fpIsInf(x)
11346 fpIsInf(x)
11347 """
11348 return _mk_fp_unary_pred(Z3_mk_fpa_is_infinite, a, ctx)
11349
11350

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

11328def fpIsNaN(a, ctx=None):
11329 """Create a Z3 floating-point isNaN expression.
11330
11331 >>> s = FPSort(8, 24)
11332 >>> x = FP('x', s)
11333 >>> y = FP('y', s)
11334 >>> fpIsNaN(x)
11335 fpIsNaN(x)
11336 """
11337 return _mk_fp_unary_pred(Z3_mk_fpa_is_nan, a, ctx)
11338
11339

◆ fpIsNegative()

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

Definition at line 11369 of file z3py.py.

11369def fpIsNegative(a, ctx=None):
11370 """Create a Z3 floating-point isNegative expression.
11371 """
11372 return _mk_fp_unary_pred(Z3_mk_fpa_is_negative, a, ctx)
11373
11374

◆ fpIsNormal()

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

Definition at line 11357 of file z3py.py.

11357def fpIsNormal(a, ctx=None):
11358 """Create a Z3 floating-point isNormal expression.
11359 """
11360 return _mk_fp_unary_pred(Z3_mk_fpa_is_normal, a, ctx)
11361
11362

◆ fpIsPositive()

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

Definition at line 11375 of file z3py.py.

11375def fpIsPositive(a, ctx=None):
11376 """Create a Z3 floating-point isPositive expression.
11377 """
11378 return _mk_fp_unary_pred(Z3_mk_fpa_is_positive, a, ctx)
11379
11380

◆ fpIsSubnormal()

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

Definition at line 11363 of file z3py.py.

11363def fpIsSubnormal(a, ctx=None):
11364 """Create a Z3 floating-point isSubnormal expression.
11365 """
11366 return _mk_fp_unary_pred(Z3_mk_fpa_is_subnormal, a, ctx)
11367
11368

◆ fpIsZero()

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

Definition at line 11351 of file z3py.py.

11351def fpIsZero(a, ctx=None):
11352 """Create a Z3 floating-point isZero expression.
11353 """
11354 return _mk_fp_unary_pred(Z3_mk_fpa_is_zero, a, ctx)
11355
11356

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

11398def fpLEQ(a, b, ctx=None):
11399 """Create the Z3 floating-point expression `other <= self`.
11400
11401 >>> x, y = FPs('x y', FPSort(8, 24))
11402 >>> fpLEQ(x, y)
11403 x <= y
11404 >>> (x <= y).sexpr()
11405 '(fp.leq x y)'
11406 """
11407 return _mk_fp_bin_pred(Z3_mk_fpa_leq, a, b, ctx)
11408
11409

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

11386def fpLT(a, b, ctx=None):
11387 """Create the Z3 floating-point expression `other < self`.
11388
11389 >>> x, y = FPs('x y', FPSort(8, 24))
11390 >>> fpLT(x, y)
11391 x < y
11392 >>> (x < y).sexpr()
11393 '(fp.lt x y)'
11394 """
11395 return _mk_fp_bin_pred(Z3_mk_fpa_lt, a, b, ctx)
11396
11397

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

11295def fpMax(a, b, ctx=None):
11296 """Create a Z3 floating-point maximum expression.
11297
11298 >>> s = FPSort(8, 24)
11299 >>> rm = RNE()
11300 >>> x = FP('x', s)
11301 >>> y = FP('y', s)
11302 >>> fpMax(x, y)
11303 fpMax(x, y)
11304 >>> fpMax(x, y).sort()
11305 FPSort(8, 24)
11306 """
11307 return _mk_fp_bin_norm(Z3_mk_fpa_max, a, b, ctx)
11308
11309

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

11280def fpMin(a, b, ctx=None):
11281 """Create a Z3 floating-point minimum expression.
11282
11283 >>> s = FPSort(8, 24)
11284 >>> rm = RNE()
11285 >>> x = FP('x', s)
11286 >>> y = FP('y', s)
11287 >>> fpMin(x, y)
11288 fpMin(x, y)
11289 >>> fpMin(x, y).sort()
11290 FPSort(8, 24)
11291 """
11292 return _mk_fp_bin_norm(Z3_mk_fpa_min, a, b, ctx)
11293
11294

◆ fpMinusInfinity()

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

Definition at line 10965 of file z3py.py.

10965def fpMinusInfinity(s):
10966 """Create a Z3 floating-point -oo term."""
10967 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10968 return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, True), s.ctx)
10969
10970

◆ fpMinusZero()

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

Definition at line 10984 of file z3py.py.

10984def fpMinusZero(s):
10985 """Create a Z3 floating-point -0.0 term."""
10986 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10987 return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, True), s.ctx)
10988
10989
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 11236 of file z3py.py.

11236def fpMul(rm, a, b, ctx=None):
11237 """Create a Z3 floating-point multiplication expression.
11238
11239 >>> s = FPSort(8, 24)
11240 >>> rm = RNE()
11241 >>> x = FP('x', s)
11242 >>> y = FP('y', s)
11243 >>> fpMul(rm, x, y)
11244 x * y
11245 >>> fpMul(rm, x, y).sort()
11246 FPSort(8, 24)
11247 """
11248 return _mk_fp_bin(Z3_mk_fpa_mul, rm, a, b, ctx)
11249
11250

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

10931def fpNaN(s):
10932 """Create a Z3 floating-point NaN term.
10933
10934 >>> s = FPSort(8, 24)
10935 >>> set_fpa_pretty(True)
10936 >>> fpNaN(s)
10937 NaN
10938 >>> pb = get_fpa_pretty()
10939 >>> set_fpa_pretty(False)
10940 >>> fpNaN(s)
10941 fpNaN(FPSort(8, 24))
10942 >>> set_fpa_pretty(pb)
10943 """
10944 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10945 return FPNumRef(Z3_mk_fpa_nan(s.ctx_ref(), s.ast), s.ctx)
10946
10947
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 11136 of file z3py.py.

11136def fpNeg(a, ctx=None):
11137 """Create a Z3 floating-point addition expression.
11138
11139 >>> s = FPSort(8, 24)
11140 >>> rm = RNE()
11141 >>> x = FP('x', s)
11142 >>> fpNeg(x)
11143 -x
11144 >>> fpNeg(x).sort()
11145 FPSort(8, 24)
11146 """
11147 ctx = _get_ctx(ctx)
11148 [a] = _coerce_fp_expr_list([a], ctx)
11149 return FPRef(Z3_mk_fpa_neg(ctx.ref(), a.as_ast()), ctx)
11150
11151
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 11446 of file z3py.py.

11446def fpNEQ(a, b, ctx=None):
11447 """Create the Z3 floating-point expression `Not(fpEQ(other, self))`.
11448
11449 >>> x, y = FPs('x y', FPSort(8, 24))
11450 >>> fpNEQ(x, y)
11451 Not(fpEQ(x, y))
11452 >>> (x != y).sexpr()
11453 '(distinct x y)'
11454 """
11455 return Not(fpEQ(a, b, ctx))
11456
11457

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

10948def fpPlusInfinity(s):
10949 """Create a Z3 floating-point +oo term.
10950
10951 >>> s = FPSort(8, 24)
10952 >>> pb = get_fpa_pretty()
10953 >>> set_fpa_pretty(True)
10954 >>> fpPlusInfinity(s)
10955 +oo
10956 >>> set_fpa_pretty(False)
10957 >>> fpPlusInfinity(s)
10958 fpPlusInfinity(FPSort(8, 24))
10959 >>> set_fpa_pretty(pb)
10960 """
10961 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10962 return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, False), s.ctx)
10963
10964

◆ fpPlusZero()

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

Definition at line 10978 of file z3py.py.

10978def fpPlusZero(s):
10979 """Create a Z3 floating-point +0.0 term."""
10980 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10981 return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, False), s.ctx)
10982
10983

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

11563def fpRealToFP(rm, v, sort, ctx=None):
11564 """Create a Z3 floating-point conversion expression that represents the
11565 conversion from a real term to a floating-point term.
11566
11567 >>> x_r = RealVal(1.5)
11568 >>> x_fp = fpRealToFP(RNE(), x_r, Float32())
11569 >>> x_fp
11570 fpToFP(RNE(), 3/2)
11571 >>> simplify(x_fp)
11572 1.5
11573 """
11574 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
11575 _z3_assert(is_real(v), "Second argument must be a Z3 expression or real sort.")
11576 _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
11577 ctx = _get_ctx(ctx)
11578 return FPRef(Z3_mk_fpa_to_fp_real(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
11579
11580
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 11266 of file z3py.py.

11266def fpRem(a, b, ctx=None):
11267 """Create a Z3 floating-point remainder expression.
11268
11269 >>> s = FPSort(8, 24)
11270 >>> x = FP('x', s)
11271 >>> y = FP('y', s)
11272 >>> fpRem(x, y)
11273 fpRem(x, y)
11274 >>> fpRem(x, y).sort()
11275 FPSort(8, 24)
11276 """
11277 return _mk_fp_bin_norm(Z3_mk_fpa_rem, a, b, ctx)
11278
11279

◆ fpRoundToIntegral()

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

Definition at line 11322 of file z3py.py.

11322def fpRoundToIntegral(rm, a, ctx=None):
11323 """Create a Z3 floating-point roundToIntegral expression.
11324 """
11325 return _mk_fp_unary(Z3_mk_fpa_round_to_integral, rm, a, ctx)
11326
11327

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

11094def FPs(names, fpsort, ctx=None):
11095 """Return an array of floating-point constants.
11096
11097 >>> x, y, z = FPs('x y z', FPSort(8, 24))
11098 >>> x.sort()
11099 FPSort(8, 24)
11100 >>> x.sbits()
11101 24
11102 >>> x.ebits()
11103 8
11104 >>> fpMul(RNE(), fpAdd(RNE(), x, y), z)
11105 (x + y) * z
11106 """
11107 ctx = _get_ctx(ctx)
11108 if isinstance(names, str):
11109 names = names.split(" ")
11110 return [FP(name, fpsort, ctx) for name in names]
11111
11112

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

11581def fpSignedToFP(rm, v, sort, ctx=None):
11582 """Create a Z3 floating-point conversion expression that represents the
11583 conversion from a signed bit-vector term (encoding an integer) to a floating-point term.
11584
11585 >>> x_signed = BitVecVal(-5, BitVecSort(32))
11586 >>> x_fp = fpSignedToFP(RNE(), x_signed, Float32())
11587 >>> x_fp
11588 fpToFP(RNE(), 4294967291)
11589 >>> simplify(x_fp)
11590 -1.25*(2**2)
11591 """
11592 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
11593 _z3_assert(is_bv(v), "Second argument must be a Z3 bit-vector expression")
11594 _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
11595 ctx = _get_ctx(ctx)
11596 return FPRef(Z3_mk_fpa_to_fp_signed(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
11597
11598
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 10867 of file z3py.py.

10867def FPSort(ebits, sbits, ctx=None):
10868 """Return a Z3 floating-point sort of the given sizes. If `ctx=None`, then the global context is used.
10869
10870 >>> Single = FPSort(8, 24)
10871 >>> Double = FPSort(11, 53)
10872 >>> Single
10873 FPSort(8, 24)
10874 >>> x = Const('x', Single)
10875 >>> eq(x, FP('x', FPSort(8, 24)))
10876 True
10877 """
10878 ctx = _get_ctx(ctx)
10879 return FPSortRef(Z3_mk_fpa_sort(ctx.ref(), ebits, sbits), ctx)
10880
10881
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 11316 of file z3py.py.

11316def fpSqrt(rm, a, ctx=None):
11317 """Create a Z3 floating-point square root expression.
11318 """
11319 return _mk_fp_unary(Z3_mk_fpa_sqrt, rm, a, ctx)
11320
11321

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

11221def fpSub(rm, a, b, ctx=None):
11222 """Create a Z3 floating-point subtraction expression.
11223
11224 >>> s = FPSort(8, 24)
11225 >>> rm = RNE()
11226 >>> x = FP('x', s)
11227 >>> y = FP('y', s)
11228 >>> fpSub(rm, x, y)
11229 x - y
11230 >>> fpSub(rm, x, y).sort()
11231 FPSort(8, 24)
11232 """
11233 return _mk_fp_bin(Z3_mk_fpa_sub, rm, a, b, ctx)
11234
11235

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

11487def fpToFP(a1, a2=None, a3=None, ctx=None):
11488 """Create a Z3 floating-point conversion expression from other term sorts
11489 to floating-point.
11490
11491 From a bit-vector term in IEEE 754-2008 format:
11492 >>> x = FPVal(1.0, Float32())
11493 >>> x_bv = fpToIEEEBV(x)
11494 >>> simplify(fpToFP(x_bv, Float32()))
11495 1
11496
11497 From a floating-point term with different precision:
11498 >>> x = FPVal(1.0, Float32())
11499 >>> x_db = fpToFP(RNE(), x, Float64())
11500 >>> x_db.sort()
11501 FPSort(11, 53)
11502
11503 From a real term:
11504 >>> x_r = RealVal(1.5)
11505 >>> simplify(fpToFP(RNE(), x_r, Float32()))
11506 1.5
11507
11508 From a signed bit-vector term:
11509 >>> x_signed = BitVecVal(-5, BitVecSort(32))
11510 >>> simplify(fpToFP(RNE(), x_signed, Float32()))
11511 -1.25*(2**2)
11512 """
11513 ctx = _get_ctx(ctx)
11514 if is_bv(a1) and is_fp_sort(a2):
11515 return FPRef(Z3_mk_fpa_to_fp_bv(ctx.ref(), a1.ast, a2.ast), ctx)
11516 elif is_fprm(a1) and is_fp(a2) and is_fp_sort(a3):
11517 return FPRef(Z3_mk_fpa_to_fp_float(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
11518 elif is_fprm(a1) and is_real(a2) and is_fp_sort(a3):
11519 return FPRef(Z3_mk_fpa_to_fp_real(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
11520 elif is_fprm(a1) and is_bv(a2) and is_fp_sort(a3):
11521 return FPRef(Z3_mk_fpa_to_fp_signed(ctx.ref(), a1.ast, a2.ast, a3.ast), ctx)
11522 else:
11523 raise Z3Exception("Unsupported combination of arguments for conversion to floating-point term.")
11524
11525

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

11617def fpToFPUnsigned(rm, x, s, ctx=None):
11618 """Create a Z3 floating-point conversion expression, from unsigned bit-vector to floating-point expression."""
11619 if z3_debug():
11620 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
11621 _z3_assert(is_bv(x), "Second argument must be a Z3 bit-vector expression")
11622 _z3_assert(is_fp_sort(s), "Third argument must be Z3 floating-point sort")
11623 ctx = _get_ctx(ctx)
11624 return FPRef(Z3_mk_fpa_to_fp_unsigned(ctx.ref(), rm.ast, x.ast, s.ast), ctx)
11625
11626
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 11691 of file z3py.py.

11691def fpToIEEEBV(x, ctx=None):
11692 """\brief Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.
11693
11694 The size of the resulting bit-vector is automatically determined.
11695
11696 Note that IEEE 754-2008 allows multiple different representations of NaN. This conversion
11697 knows only one NaN and it will always produce the same bit-vector representation of
11698 that NaN.
11699
11700 >>> x = FP('x', FPSort(8, 24))
11701 >>> y = fpToIEEEBV(x)
11702 >>> print(is_fp(x))
11703 True
11704 >>> print(is_bv(y))
11705 True
11706 >>> print(is_fp(y))
11707 False
11708 >>> print(is_bv(x))
11709 False
11710 """
11711 if z3_debug():
11712 _z3_assert(is_fp(x), "First argument must be a Z3 floating-point expression")
11713 ctx = _get_ctx(ctx)
11714 return BitVecRef(Z3_mk_fpa_to_ieee_bv(ctx.ref(), x.ast), ctx)
11715
11716
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 11671 of file z3py.py.

11671def fpToReal(x, ctx=None):
11672 """Create a Z3 floating-point conversion expression, from floating-point expression to real.
11673
11674 >>> x = FP('x', FPSort(8, 24))
11675 >>> y = fpToReal(x)
11676 >>> print(is_fp(x))
11677 True
11678 >>> print(is_real(y))
11679 True
11680 >>> print(is_fp(y))
11681 False
11682 >>> print(is_real(x))
11683 False
11684 """
11685 if z3_debug():
11686 _z3_assert(is_fp(x), "First argument must be a Z3 floating-point expression")
11687 ctx = _get_ctx(ctx)
11688 return ArithRef(Z3_mk_fpa_to_real(ctx.ref(), x.ast), ctx)
11689
11690
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 11627 of file z3py.py.

11627def fpToSBV(rm, x, s, ctx=None):
11628 """Create a Z3 floating-point conversion expression, from floating-point expression to signed bit-vector.
11629
11630 >>> x = FP('x', FPSort(8, 24))
11631 >>> y = fpToSBV(RTZ(), x, BitVecSort(32))
11632 >>> print(is_fp(x))
11633 True
11634 >>> print(is_bv(y))
11635 True
11636 >>> print(is_fp(y))
11637 False
11638 >>> print(is_bv(x))
11639 False
11640 """
11641 if z3_debug():
11642 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
11643 _z3_assert(is_fp(x), "Second argument must be a Z3 floating-point expression")
11644 _z3_assert(is_bv_sort(s), "Third argument must be Z3 bit-vector sort")
11645 ctx = _get_ctx(ctx)
11646 return BitVecRef(Z3_mk_fpa_to_sbv(ctx.ref(), rm.ast, x.ast, s.size()), ctx)
11647
11648
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 11649 of file z3py.py.

11649def fpToUBV(rm, x, s, ctx=None):
11650 """Create a Z3 floating-point conversion expression, from floating-point expression to unsigned bit-vector.
11651
11652 >>> x = FP('x', FPSort(8, 24))
11653 >>> y = fpToUBV(RTZ(), x, BitVecSort(32))
11654 >>> print(is_fp(x))
11655 True
11656 >>> print(is_bv(y))
11657 True
11658 >>> print(is_fp(y))
11659 False
11660 >>> print(is_bv(x))
11661 False
11662 """
11663 if z3_debug():
11664 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
11665 _z3_assert(is_fp(x), "Second argument must be a Z3 floating-point expression")
11666 _z3_assert(is_bv_sort(s), "Third argument must be Z3 bit-vector sort")
11667 ctx = _get_ctx(ctx)
11668 return BitVecRef(Z3_mk_fpa_to_ubv(ctx.ref(), rm.ast, x.ast, s.size()), ctx)
11669
11670
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 11599 of file z3py.py.

11599def fpUnsignedToFP(rm, v, sort, ctx=None):
11600 """Create a Z3 floating-point conversion expression that represents the
11601 conversion from an unsigned bit-vector term (encoding an integer) to a floating-point term.
11602
11603 >>> x_signed = BitVecVal(-5, BitVecSort(32))
11604 >>> x_fp = fpUnsignedToFP(RNE(), x_signed, Float32())
11605 >>> x_fp
11606 fpToFPUnsigned(RNE(), 4294967291)
11607 >>> simplify(x_fp)
11608 1*(2**32)
11609 """
11610 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
11611 _z3_assert(is_bv(v), "Second argument must be a Z3 bit-vector expression")
11612 _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
11613 ctx = _get_ctx(ctx)
11614 return FPRef(Z3_mk_fpa_to_fp_unsigned(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
11615
11616

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

10997def FPVal(sig, exp=None, fps=None, ctx=None):
10998 """Return a floating-point value of value `sig * 2**exp` and sort `fps`.
10999 If `exp=None`, then the exponent is zero.
11000 If `ctx=None`, then the global context is used.
11001
11002 >>> v = FPVal(20.0, FPSort(8, 24))
11003 >>> v
11004 1.25*(2**4)
11005 >>> print("0x%.8x" % v.exponent_as_long(False))
11006 0x00000004
11007 >>> v = FPVal(2.25, FPSort(8, 24))
11008 >>> v
11009 1.125*(2**1)
11010 >>> v = FPVal(-2.25, FPSort(8, 24))
11011 >>> v
11012 -1.125*(2**1)
11013 >>> FPVal(-0.0, FPSort(8, 24))
11014 -0.0
11015 >>> FPVal(0.0, FPSort(8, 24))
11016 +0.0
11017 >>> FPVal(+0.0, FPSort(8, 24))
11018 +0.0
11019 >>> FPVal(1.0, 3, Float32())
11020 1*(2**3)
11021 >>> FPVal(1, 3, Float32())
11022 1*(2**3)
11023 >>> FPVal("1.5", -2, Float32())
11024 1.5*(2**-2)
11025 >>> FPVal("1.25*(2**4)", 1, Float32())
11026 1.25*(2**5)
11027 >>> FPVal("1.25*(2**4)", -4, Float32())
11028 1.25
11029 >>> FPVal("1p2", 3, Float32())
11030 1*(2**5)
11031 >>> FPVal("1P2", 3, Float32())
11032 1*(2**5)
11033 >>> FPVal("1.5p-2", 2, Float32())
11034 1.5
11035 >>> FPVal(1.5, 0, Float32())
11036 1.5
11037 >>> FPVal(1.5, fps=Float32())
11038 1.5
11039 >>> [FPVal(v, 3, Float32()) for v in
11040 ... [float("nan"), float("inf"), float("-inf"), 0.0, -0.0]]
11041 [NaN, +oo, -oo, +0.0, -0.0]
11042 >>> [FPVal(v, -2, Float32()) for v in
11043 ... ["NaN", "+oo", "-oo", "+0.0", "-0.0"]]
11044 [NaN, +oo, -oo, +0.0, -0.0]
11045 """
11046 ctx = _get_ctx(ctx)
11047 if is_fp_sort(exp):
11048 fps = exp
11049 exp = None
11050 elif fps is None:
11051 fps = _dflt_fps(ctx)
11052 _z3_assert(is_fp_sort(fps), "sort mismatch")
11053 if exp is None:
11054 exp = 0
11055 val = _to_float_str(sig)
11056 if val == "NaN" or val == "nan":
11057 return fpNaN(fps)
11058 elif val == "-0.0":
11059 return fpMinusZero(fps)
11060 elif val == "0.0" or val == "+0.0":
11061 return fpPlusZero(fps)
11062 elif val == "+oo" or val == "+inf" or val == "+Inf":
11063 return fpPlusInfinity(fps)
11064 elif val == "-oo" or val == "-inf" or val == "-Inf":
11065 return fpMinusInfinity(fps)
11066 else:
11067 return FPNumRef(Z3_mk_numeral(ctx.ref(), _to_float_str(sig, exp), fps.ast), ctx)
11068
11069

◆ fpZero()

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

Definition at line 10990 of file z3py.py.

10990def fpZero(s, negative):
10991 """Create a Z3 floating-point +0.0 or -0.0 term."""
10992 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10993 _z3_assert(isinstance(negative, bool), "expected Boolean flag")
10994 return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, negative), s.ctx)
10995
10996

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

1931def FreshBool(prefix="b", ctx=None):
1932 """Return a fresh Boolean constant in the given context using the given prefix.
1933
1934 If `ctx=None`, then the global context is used.
1935
1936 >>> b1 = FreshBool()
1937 >>> b2 = FreshBool()
1938 >>> eq(b1, b2)
1939 False
1940 """
1941 ctx = _get_ctx(ctx)
1942 return BoolRef(Z3_mk_fresh_const(ctx.ref(), prefix, BoolSort(ctx).ast), ctx)
1943
1944
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 1594 of file z3py.py.

1594def FreshConst(sort, prefix="c"):
1595 """Create a fresh constant of a specified sort"""
1596 if z3_debug():
1597 _z3_assert(is_sort(sort), f"Z3 sort expected, got {type(sort)}")
1598 ctx = _get_ctx(sort.ctx)
1599 return _to_expr_ref(Z3_mk_fresh_const(ctx.ref(), prefix, sort.ast), ctx)
1600
1601

◆ FreshFunction()

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

Definition at line 951 of file z3py.py.

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

3568def FreshInt(prefix="x", ctx=None):
3569 """Return a fresh integer constant in the given context using the given prefix.
3570
3571 >>> x = FreshInt()
3572 >>> y = FreshInt()
3573 >>> eq(x, y)
3574 False
3575 >>> x.sort()
3576 Int
3577 """
3578 ctx = _get_ctx(ctx)
3579 return ArithRef(Z3_mk_fresh_const(ctx.ref(), prefix, IntSort(ctx).ast), ctx)
3580
3581

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

3625def FreshReal(prefix="b", ctx=None):
3626 """Return a fresh real constant in the given context using the given prefix.
3627
3628 >>> x = FreshReal()
3629 >>> y = FreshReal()
3630 >>> eq(x, y)
3631 False
3632 >>> x.sort()
3633 Real
3634 """
3635 ctx = _get_ctx(ctx)
3636 return ArithRef(Z3_mk_fresh_const(ctx.ref(), prefix, RealSort(ctx).ast), ctx)
3637
3638

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

11997def Full(s):
11998 """Create the regular expression that accepts the universal language
11999 >>> e = Full(ReSort(SeqSort(IntSort())))
12000 >>> print(e)
12001 Full(ReSort(Seq(Int)))
12002 >>> e1 = Full(ReSort(StringSort()))
12003 >>> print(e1)
12004 Full(ReSort(String))
12005 """
12006 if isinstance(s, ReSortRef):
12007 return ReRef(Z3_mk_re_full(s.ctx_ref(), s.ast), s.ctx)
12008 raise Z3Exception("Non-sequence, non-regular expression sort passed to Full")
12009
12010
12011
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 5297 of file z3py.py.

5297def FullSet(s):
5298 """Create the full set
5299 >>> FullSet(IntSort())
5300 K(Int, True)
5301 """
5302 ctx = s.ctx
5303 return ArrayRef(Z3_mk_full_set(ctx.ref(), s.ast), ctx)
5304
5305
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 928 of file z3py.py.

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

7483def get_as_array_func(n):
7484 """Return the function declaration f associated with a Z3 expression of the form (_ as-array f)."""
7485 if z3_debug():
7486 _z3_assert(is_as_array(n), "as-array Z3 expression expected.")
7487 return FuncDeclRef(Z3_get_as_array_func_decl(n.ctx.ref(), n.as_ast()), n.ctx)
7488
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 10279 of file z3py.py.

10279def get_default_fp_sort(ctx=None):
10280 return FPSort(_dflt_fpsort_ebits, _dflt_fpsort_sbits, ctx)
10281
10282

◆ get_default_rounding_mode()

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

Definition at line 10246 of file z3py.py.

10246def get_default_rounding_mode(ctx=None):
10247 """Retrieves the global default rounding mode."""
10248 global _dflt_rounding_mode
10249 if _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO:
10250 return RTZ(ctx)
10251 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE:
10252 return RTN(ctx)
10253 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE:
10254 return RTP(ctx)
10255 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN:
10256 return RNE(ctx)
10257 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY:
10258 return RNA(ctx)
10259
10260

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

5026def get_map_func(a):
5027 """Return the function declaration associated with a Z3 map array expression.
5028
5029 >>> f = Function('f', IntSort(), IntSort())
5030 >>> b = Array('b', IntSort(), IntSort())
5031 >>> a = Map(f, b)
5032 >>> eq(f, get_map_func(a))
5033 True
5034 >>> get_map_func(a)
5035 f
5036 >>> get_map_func(a)(0)
5037 f(0)
5038 """
5039 if z3_debug():
5040 _z3_assert(is_map(a), "Z3 array map expression expected.")
5041 return FuncDeclRef(
5043 a.ctx_ref(),
5044 Z3_get_decl_ast_parameter(a.ctx_ref(), a.decl().ast, 0),
5045 ),
5046 ctx=a.ctx,
5047 )
5048
5049
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 1465 of file z3py.py.

1465def get_var_index(a):
1466 """Return the de-Bruijn index of the Z3 bounded variable `a`.
1467
1468 >>> x = Int('x')
1469 >>> y = Int('y')
1470 >>> is_var(x)
1471 False
1472 >>> is_const(x)
1473 True
1474 >>> f = Function('f', IntSort(), IntSort(), IntSort())
1475 >>> # Z3 replaces x and y with bound variables when ForAll is executed.
1476 >>> q = ForAll([x, y], f(x, y) == x + y)
1477 >>> q.body()
1478 f(Var(1), Var(0)) == Var(1) + Var(0)
1479 >>> b = q.body()
1480 >>> b.arg(0)
1481 f(Var(1), Var(0))
1482 >>> v1 = b.arg(0).arg(0)
1483 >>> v2 = b.arg(0).arg(1)
1484 >>> v1
1485 Var(1)
1486 >>> v2
1487 Var(0)
1488 >>> get_var_index(v1)
1489 1
1490 >>> get_var_index(v2)
1491 0
1492 """
1493 if z3_debug():
1494 _z3_assert(is_var(a), "Z3 bound variable expected")
1495 return int(Z3_get_index_value(a.ctx.ref(), a.as_ast()))
1496
1497
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 9752 of file z3py.py.

9752def help_simplify():
9753 """Return a string describing all options available for Z3 `simplify` procedure."""
9754 print(Z3_simplify_get_help(main_ctx().ref()))
9755
9756
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 1511 of file z3py.py.

1511def If(a, b, c, ctx=None):
1512 """Create a Z3 if-then-else expression.
1513
1514 >>> x = Int('x')
1515 >>> y = Int('y')
1516 >>> max = If(x > y, x, y)
1517 >>> max
1518 If(x > y, x, y)
1519 >>> simplify(max)
1520 If(x <= y, y, x)
1521 """
1522 if isinstance(a, Probe) or isinstance(b, Tactic) or isinstance(c, Tactic):
1523 return Cond(a, b, c, ctx)
1524 else:
1525 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b, c], ctx))
1526 s = BoolSort(ctx)
1527 a = s.cast(a)
1528 b, c = _coerce_exprs(b, c, ctx)
1529 if z3_debug():
1530 _z3_assert(a.ctx == b.ctx, "Context mismatch")
1531 return _to_expr_ref(Z3_mk_ite(ctx.ref(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
1532
1533
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().

◆ ImagPart()

ImagPart ( value)
Return the Real-valued imaginary component of a Complex expression.

Definition at line 3396 of file z3py.py.

3396def ImagPart(value):
3397 """Return the Real-valued imaginary component of a Complex expression."""
3398 _z3_assert(is_complex(value), "Complex expression expected")
3399 return _to_expr_ref(Z3_mk_imag_part(value.ctx_ref(), value.as_ast()), value.ctx)
3400
3401
Z3_ast Z3_API Z3_mk_imag_part(Z3_context c, Z3_ast z)
Return the imaginary component of a Complex expression.

Referenced by ComplexRef.imag_part().

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

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

5571def In(elem, set):
5572 return FiniteSetMember(elem, set)
5573

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

12081def IndexOf(s, substr, offset=None):
12082 """Retrieve the index of substring within a string starting at a specified offset.
12083 >>> simplify(IndexOf("abcabc", "bc", 0))
12084 1
12085 >>> simplify(IndexOf("abcabc", "bc", 2))
12086 4
12087 """
12088 if offset is None:
12089 offset = IntVal(0)
12090 ctx = None
12091 if is_expr(offset):
12092 ctx = offset.ctx
12093 ctx = _get_ctx2(s, substr, ctx)
12094 s = _coerce_seq(s, ctx)
12095 substr = _coerce_seq(substr, ctx)
12096 if _is_int(offset):
12097 offset = IntVal(offset, ctx)
12098 return ArithRef(Z3_mk_seq_index(s.ctx_ref(), s.as_ast(), substr.as_ast(), offset.as_ast()), s.ctx)
12099
12100
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 12230 of file z3py.py.

12230def InRe(s, re):
12231 """Create regular expression membership test
12232 >>> re = Union(Re("a"),Re("b"))
12233 >>> print (simplify(InRe("a", re)))
12234 True
12235 >>> print (simplify(InRe("b", re)))
12236 True
12237 >>> print (simplify(InRe("c", re)))
12238 False
12239 """
12240 s = _coerce_seq(s, re.ctx)
12241 return BoolRef(Z3_mk_seq_in_re(s.ctx_ref(), s.as_ast(), re.as_ast()), s.ctx)
12242
12243
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 3529 of file z3py.py.

3529def Int(name, ctx=None):
3530 """Return an integer constant named `name`. If `ctx=None`, then the global context is used.
3531
3532 >>> x = Int('x')
3533 >>> is_int(x)
3534 True
3535 >>> is_int(x + 1)
3536 True
3537 """
3538 ctx = _get_ctx(ctx)
3539 return ArithRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), IntSort(ctx).ast), ctx)
3540
3541

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

4284def Int2BV(a, num_bits):
4285 """Return the z3 expression Int2BV(a, num_bits).
4286 It is a bit-vector of width num_bits and represents the
4287 modulo of a by 2^num_bits
4288 """
4289 ctx = a.ctx
4290 return BitVecRef(Z3_mk_int2bv(ctx.ref(), num_bits, a.as_ast()), ctx)
4291
4292
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 12272 of file z3py.py.

12272def Intersect(*args):
12273 """Create intersection of regular expressions.
12274 >>> re = Intersect(Re("a"), Re("b"), Re("c"))
12275 """
12276 args = _get_args(args)
12277 sz = len(args)
12278 if z3_debug():
12279 _z3_assert(sz > 0, "At least one argument expected.")
12280 arg0 = args[0]
12281 if is_finite_set(arg0):
12282 for a in args[1:]:
12283 if not is_finite_set(a):
12284 raise Z3Exception("All arguments must be regular expressions or finite sets.")
12285 arg0 = arg0 & a
12286 return arg0
12287 if z3_debug():
12288 _z3_assert(all([is_re(a) for a in args]), "All arguments must be regular expressions.")
12289 if sz == 1:
12290 return args[0]
12291 ctx = args[0].ctx
12292 v = (Ast * sz)()
12293 for i in range(sz):
12294 v[i] = args[i].as_ast()
12295 return ReRef(Z3_mk_re_intersect(ctx.ref(), sz, v), ctx)
12296
12297
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 3542 of file z3py.py.

3542def Ints(names, ctx=None):
3543 """Return a tuple of Integer constants.
3544
3545 >>> x, y, z = Ints('x y z')
3546 >>> Sum(x, y, z)
3547 x + y + z
3548 """
3549 ctx = _get_ctx(ctx)
3550 if isinstance(names, str):
3551 names = names.split(" ")
3552 return [Int(name, ctx) for name in names]
3553
3554

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

3419def IntSort(ctx=None):
3420 """Return the integer sort in the given context. If `ctx=None`, then the global context is used.
3421
3422 >>> IntSort()
3423 Int
3424 >>> x = Const('x', IntSort())
3425 >>> is_int(x)
3426 True
3427 >>> x.sort() == IntSort()
3428 True
3429 >>> x.sort() == BoolSort()
3430 False
3431 """
3432 ctx = _get_ctx(ctx)
3433 return ArithSortRef(Z3_mk_int_sort(ctx.ref()), ctx)
3434
3435
Z3_sort Z3_API Z3_mk_int_sort(Z3_context c)
Create the integer type.

Referenced by FreshInt(), and Int().

◆ IntToStr()

IntToStr ( s)
Convert integer expression to string

Definition at line 12172 of file z3py.py.

12172def IntToStr(s):
12173 """Convert integer expression to string"""
12174 if not is_expr(s):
12175 s = _py2expr(s)
12176 return SeqRef(Z3_mk_int_to_str(s.ctx_ref(), s.as_ast()), s.ctx)
12177
12178
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 3465 of file z3py.py.

3465def IntVal(val, ctx=None):
3466 """Return a Z3 integer value. If `ctx=None`, then the global context is used.
3467
3468 >>> IntVal(1)
3469 1
3470 >>> IntVal("100")
3471 100
3472 """
3473 ctx = _get_ctx(ctx)
3474 return IntNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), Z3_mk_int_sort(ctx.ref())), ctx)
3475
3476

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

3555def IntVector(prefix, sz, ctx=None):
3556 """Return a list of integer constants of size `sz`.
3557
3558 >>> X = IntVector('x', 3)
3559 >>> X
3560 [x__0, x__1, x__2]
3561 >>> Sum(X)
3562 x__0 + x__1 + x__2
3563 """
3564 ctx = _get_ctx(ctx)
3565 return [Int("%s__%s" % (prefix, i), ctx) for i in range(sz)]
3566
3567

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

2974def is_add(a : Any) -> bool:
2975 """Return `True` if `a` is an expression of the form b + c.
2976
2977 >>> x, y = Ints('x y')
2978 >>> is_add(x + y)
2979 True
2980 >>> is_add(x - y)
2981 False
2982 """
2983 return is_app_of(a, Z3_OP_ADD)
2984
2985

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

2960def is_algebraic_value(a):
2961 """Return `True` if `a` is an algebraic value of sort Real.
2962
2963 >>> is_algebraic_value(RealVal("3/5"))
2964 False
2965 >>> n = simplify(Sqrt(2))
2966 >>> n
2967 1.4142135623?
2968 >>> is_algebraic_value(n)
2969 True
2970 """
2971 return is_arith(a) and a.is_real() and _is_algebraic(a.ctx, a.as_ast())
2972
2973

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

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

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

1395def is_app(a):
1396 """Return `True` if `a` is a Z3 function application.
1397
1398 Note that, constants are function applications with 0 arguments.
1399
1400 >>> a = Int('a')
1401 >>> is_app(a)
1402 True
1403 >>> is_app(a + 1)
1404 True
1405 >>> is_app(IntSort())
1406 False
1407 >>> is_app(1)
1408 False
1409 >>> is_app(IntVal(1))
1410 True
1411 >>> x = Int('x')
1412 >>> is_app(ForAll(x, x >= 0))
1413 False
1414 """
1415 if not isinstance(a, ExprRef):
1416 return False
1417 k = _ast_kind(a.ctx, a)
1418 return k == Z3_NUMERAL_AST or k == Z3_APP_AST
1419
1420

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

1498def is_app_of(a, k):
1499 """Return `True` if `a` is an application of the given kind `k`.
1500
1501 >>> x = Int('x')
1502 >>> n = x + 1
1503 >>> is_app_of(n, Z3_OP_ADD)
1504 True
1505 >>> is_app_of(n, Z3_OP_MUL)
1506 False
1507 """
1508 return is_app(a) and a.kind() == k
1509
1510

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

2847def is_arith(a):
2848 """Return `True` if `a` is an arithmetical expression.
2849
2850 >>> x = Int('x')
2851 >>> is_arith(x)
2852 True
2853 >>> is_arith(x + 1)
2854 True
2855 >>> is_arith(1)
2856 False
2857 >>> is_arith(IntVal(1))
2858 True
2859 >>> y = Real('y')
2860 >>> is_arith(y)
2861 True
2862 >>> is_arith(y + 1)
2863 True
2864 """
2865 return isinstance(a, ArithRef)
2866
2867

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

2535def is_arith_sort(s : Any) -> bool:
2536 """Return `True` if s is an arithmetical sort (type).
2537
2538 >>> is_arith_sort(IntSort())
2539 True
2540 >>> is_arith_sort(RealSort())
2541 True
2542 >>> is_arith_sort(BoolSort())
2543 False
2544 >>> n = Int('x') + 1
2545 >>> is_arith_sort(n.sort())
2546 True
2547 """
2548 return isinstance(s, ArithSortRef)
2549
2550

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

4961def is_array(a : Any) -> bool:
4962 """Return `True` if `a` is a Z3 array expression.
4963
4964 >>> a = Array('a', IntSort(), IntSort())
4965 >>> is_array(a)
4966 True
4967 >>> is_array(Store(a, 0, 1))
4968 True
4969 >>> is_array(a[0])
4970 False
4971 """
4972 return isinstance(a, ArrayRef)
4973
4974

Referenced by Ext(), and Map().

◆ is_array_sort()

is_array_sort ( a)

Definition at line 4957 of file z3py.py.

4957def is_array_sort(a):
4958 return Z3_get_sort_kind(a.ctx.ref(), Z3_get_sort(a.ctx.ref(), a.ast)) == Z3_ARRAY_SORT
4959
4960

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

7478def is_as_array(n):
7479 """Return true if n is a Z3 expression of the form (_ as-array f)."""
7480 return isinstance(n, ExprRef) and Z3_is_as_array(n.ctx.ref(), n.as_ast())
7481
7482
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 1731 of file z3py.py.

1731def is_bool(a : Any) -> bool:
1732 """Return `True` if `a` is a Z3 Boolean expression.
1733
1734 >>> p = Bool('p')
1735 >>> is_bool(p)
1736 True
1737 >>> q = Bool('q')
1738 >>> is_bool(And(p, q))
1739 True
1740 >>> x = Real('x')
1741 >>> is_bool(x)
1742 False
1743 >>> is_bool(x == 0)
1744 True
1745 """
1746 return isinstance(a, BoolRef)
1747
1748

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

4232def is_bv(a):
4233 """Return `True` if `a` is a Z3 bit-vector expression.
4234
4235 >>> b = BitVec('b', 32)
4236 >>> is_bv(b)
4237 True
4238 >>> is_bv(b + 10)
4239 True
4240 >>> is_bv(Int('x'))
4241 False
4242 """
4243 return isinstance(a, BitVecRef)
4244
4245

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

3759def is_bv_sort(s):
3760 """Return True if `s` is a Z3 bit-vector sort.
3761
3762 >>> is_bv_sort(BitVecSort(32))
3763 True
3764 >>> is_bv_sort(IntSort())
3765 False
3766 """
3767 return isinstance(s, BitVecSortRef)
3768
3769

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

4246def is_bv_value(a):
4247 """Return `True` if `a` is a Z3 bit-vector numeral value.
4248
4249 >>> b = BitVec('b', 32)
4250 >>> is_bv_value(b)
4251 False
4252 >>> b = BitVecVal(10, 32)
4253 >>> b
4254 10
4255 >>> is_bv_value(b)
4256 True
4257 """
4258 return is_bv(a) and _is_numeral(a.ctx, a.as_ast())
4259
4260

◆ is_complex()

is_complex ( a)
Return whether `a` is a Complex expression.

Definition at line 3346 of file z3py.py.

3346def is_complex(a):
3347 """Return whether `a` is a Complex expression."""
3348 return isinstance(a, ComplexRef)
3349
3350

Referenced by ImagPart(), and RealPart().

◆ is_complex_sort()

is_complex_sort ( s)
Return whether `s` is a Complex sort.

Definition at line 3341 of file z3py.py.

3341def is_complex_sort(s):
3342 """Return whether `s` is a Complex sort."""
3343 return isinstance(s, ComplexSortRef)
3344
3345

Referenced by ArithSortRef.subsort().

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

1421def is_const(a):
1422 """Return `True` if `a` is Z3 constant/variable expression.
1423
1424 >>> a = Int('a')
1425 >>> is_const(a)
1426 True
1427 >>> is_const(a + 1)
1428 False
1429 >>> is_const(1)
1430 False
1431 >>> is_const(IntVal(1))
1432 True
1433 >>> x = Int('x')
1434 >>> is_const(ForAll(x, x >= 0))
1435 False
1436 """
1437 return is_app(a) and a.num_args() == 0
1438
1439

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

4975def is_const_array(a):
4976 """Return `True` if `a` is a Z3 constant array.
4977
4978 >>> a = K(IntSort(), 10)
4979 >>> is_const_array(a)
4980 True
4981 >>> a = Array('a', IntSort(), IntSort())
4982 >>> is_const_array(a)
4983 False
4984 """
4985 return is_app_of(a, Z3_OP_CONST_ARRAY)
4986
4987

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

5017def is_default(a):
5018 """Return `True` if `a` is a Z3 default array expression.
5019 >>> d = Default(K(IntSort(), 10))
5020 >>> is_default(d)
5021 True
5022 """
5023 return is_app_of(a, Z3_OP_ARRAY_DEFAULT)
5024
5025

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

1839def is_distinct(a : Any) -> bool:
1840 """Return `True` if `a` is a Z3 distinct expression.
1841
1842 >>> x, y, z = Ints('x y z')
1843 >>> is_distinct(x == y)
1844 False
1845 >>> is_distinct(Distinct(x, y, z))
1846 True
1847 """
1848 return is_app_of(a, Z3_OP_DISTINCT)
1849
1850

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

3010def is_div(a : Any) -> bool:
3011 """Return `True` if `a` is an expression of the form b / c.
3012
3013 >>> x, y = Reals('x y')
3014 >>> is_div(x / y)
3015 True
3016 >>> is_div(x + y)
3017 False
3018 >>> x, y = Ints('x y')
3019 >>> is_div(x / y)
3020 False
3021 >>> is_idiv(x / y)
3022 True
3023 """
3024 return is_app_of(a, Z3_OP_DIV)
3025
3026

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

1829def is_eq(a : Any) -> bool:
1830 """Return `True` if `a` is a Z3 equality expression.
1831
1832 >>> x, y = Ints('x y')
1833 >>> is_eq(x == y)
1834 True
1835 """
1836 return is_app_of(a, Z3_OP_EQ)
1837
1838

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

1372def is_expr(a):
1373 """Return `True` if `a` is a Z3 expression.
1374
1375 >>> a = Int('a')
1376 >>> is_expr(a)
1377 True
1378 >>> is_expr(a + 1)
1379 True
1380 >>> is_expr(IntSort())
1381 False
1382 >>> is_expr(1)
1383 False
1384 >>> is_expr(IntVal(1))
1385 True
1386 >>> x = Int('x')
1387 >>> is_expr(ForAll(x, x >= 0))
1388 True
1389 >>> is_expr(FPVal(1.0))
1390 True
1391 """
1392 return isinstance(a, ExprRef)
1393
1394

Referenced by _coerce_expr_list(), _coerce_expr_merge(), _coerce_exprs(), _mk_quantifier(), _py2expr(), ArithSortRef.cast(), BitVecSortRef.cast(), ComplexSortRef.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 1767 of file z3py.py.

1767def is_false(a : Any) -> bool:
1768 """Return `True` if `a` is the Z3 false expression.
1769
1770 >>> p = Bool('p')
1771 >>> is_false(p)
1772 False
1773 >>> is_false(False)
1774 False
1775 >>> is_false(BoolVal(False))
1776 True
1777 """
1778 return is_app_of(a, Z3_OP_FALSE)
1779
1780

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

8597def is_finite_domain(a):
8598 """Return `True` if `a` is a Z3 finite-domain expression.
8599
8600 >>> s = FiniteDomainSort('S', 100)
8601 >>> b = Const('b', s)
8602 >>> is_finite_domain(b)
8603 True
8604 >>> is_finite_domain(Int('x'))
8605 False
8606 """
8607 return isinstance(a, FiniteDomainRef)
8608
8609

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

8574def is_finite_domain_sort(s):
8575 """Return True if `s` is a Z3 finite-domain sort.
8576
8577 >>> is_finite_domain_sort(FiniteDomainSort('S', 100))
8578 True
8579 >>> is_finite_domain_sort(IntSort())
8580 False
8581 """
8582 return isinstance(s, FiniteDomainSortRef)
8583
8584

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

8651def is_finite_domain_value(a):
8652 """Return `True` if `a` is a Z3 finite-domain value.
8653
8654 >>> s = FiniteDomainSort('S', 100)
8655 >>> b = Const('b', s)
8656 >>> is_finite_domain_value(b)
8657 False
8658 >>> b = FiniteDomainVal(10, s)
8659 >>> b
8660 10
8661 >>> is_finite_domain_value(b)
8662 True
8663 """
8664 return is_finite_domain(a) and _is_numeral(a.ctx, a.as_ast())
8665
8666

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

5461def is_finite_set(a):
5462 """Return True if a is a Z3 finite set expression.
5463 >>> s = FiniteSetSort(IntSort())
5464 >>> is_finite_set(FiniteSetEmpty(s))
5465 True
5466 >>> is_finite_set(IntVal(1))
5467 False
5468 """
5469 return isinstance(a, FiniteSetRef)
5470
5471

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

5472def is_finite_set_sort(s):
5473 """Return True if s is a Z3 finite set sort.
5474 >>> is_finite_set_sort(FiniteSetSort(IntSort()))
5475 True
5476 >>> is_finite_set_sort(IntSort())
5477 False
5478 """
5479 return isinstance(s, FiniteSetSortRef)
5480
5481

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

10838def is_fp(a):
10839 """Return `True` if `a` is a Z3 floating-point expression.
10840
10841 >>> b = FP('b', FPSort(8, 24))
10842 >>> is_fp(b)
10843 True
10844 >>> is_fp(b + 1.0)
10845 True
10846 >>> is_fp(Int('x'))
10847 False
10848 """
10849 return isinstance(a, FPRef)
10850
10851

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

10412def is_fp_sort(s):
10413 """Return True if `s` is a Z3 floating-point sort.
10414
10415 >>> is_fp_sort(FPSort(8, 24))
10416 True
10417 >>> is_fp_sort(IntSort())
10418 False
10419 """
10420 return isinstance(s, FPSortRef)
10421
10422

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

10852def is_fp_value(a):
10853 """Return `True` if `a` is a Z3 floating-point numeral value.
10854
10855 >>> b = FP('b', FPSort(8, 24))
10856 >>> is_fp_value(b)
10857 False
10858 >>> b = FPVal(1.0, FPSort(8, 24))
10859 >>> b
10860 1
10861 >>> is_fp_value(b)
10862 True
10863 """
10864 return is_fp(a) and _is_numeral(a.ctx, a.ast)
10865
10866

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

10672def is_fprm(a):
10673 """Return `True` if `a` is a Z3 floating-point rounding mode expression.
10674
10675 >>> rm = RNE()
10676 >>> is_fprm(rm)
10677 True
10678 >>> rm = 1.0
10679 >>> is_fprm(rm)
10680 False
10681 """
10682 return isinstance(a, FPRMRef)
10683
10684

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

10423def is_fprm_sort(s):
10424 """Return True if `s` is a Z3 floating-point rounding mode sort.
10425
10426 >>> is_fprm_sort(FPSort(8, 24))
10427 False
10428 >>> is_fprm_sort(RNE().sort())
10429 True
10430 """
10431 return isinstance(s, FPRMSortRef)
10432
10433# FP Expressions
10434
10435

◆ is_fprm_value()

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

Definition at line 10685 of file z3py.py.

10685def is_fprm_value(a):
10686 """Return `True` if `a` is a Z3 floating-point rounding mode numeral value."""
10687 return is_fprm(a) and _is_numeral(a.ctx, a.ast)
10688
10689# FP Numerals
10690
10691

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

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

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

3075def is_ge(a : Any) -> bool:
3076 """Return `True` if `a` is an expression of the form b >= c.
3077
3078 >>> x, y = Ints('x y')
3079 >>> is_ge(x >= y)
3080 True
3081 >>> is_ge(x == y)
3082 False
3083 """
3084 return is_app_of(a, Z3_OP_GE)
3085
3086

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

3087def is_gt(a : Any) -> bool:
3088 """Return `True` if `a` is an expression of the form b > c.
3089
3090 >>> x, y = Ints('x y')
3091 >>> is_gt(x > y)
3092 True
3093 >>> is_gt(x == y)
3094 False
3095 """
3096 return is_app_of(a, Z3_OP_GT)
3097
3098

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

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

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

1805def is_implies(a : Any) -> bool:
1806 """Return `True` if `a` is a Z3 implication expression.
1807
1808 >>> p, q = Bools('p q')
1809 >>> is_implies(Implies(p, q))
1810 True
1811 >>> is_implies(And(p, q))
1812 False
1813 """
1814 return is_app_of(a, Z3_OP_IMPLIES)
1815
1816

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

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

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

2914def is_int_value(a):
2915 """Return `True` if `a` is an integer value of sort Int.
2916
2917 >>> is_int_value(IntVal(1))
2918 True
2919 >>> is_int_value(1)
2920 False
2921 >>> is_int_value(Int('x'))
2922 False
2923 >>> n = Int('x') + 1
2924 >>> n
2925 x + 1
2926 >>> n.arg(1)
2927 1
2928 >>> is_int_value(n.arg(1))
2929 True
2930 >>> is_int_value(RealVal("1/3"))
2931 False
2932 >>> is_int_value(RealVal(1))
2933 False
2934 """
2935 return is_arith(a) and a.is_int() and _is_numeral(a.ctx, a.as_ast())
2936
2937

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

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

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

4988def is_K(a):
4989 """Return `True` if `a` is a Z3 constant array.
4990
4991 >>> a = K(IntSort(), 10)
4992 >>> is_K(a)
4993 True
4994 >>> a = Array('a', IntSort(), IntSort())
4995 >>> is_K(a)
4996 False
4997 """
4998 return is_app_of(a, Z3_OP_CONST_ARRAY)
4999
5000

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

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

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

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

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

5001def is_map(a):
5002 """Return `True` if `a` is a Z3 map array expression.
5003
5004 >>> f = Function('f', IntSort(), IntSort())
5005 >>> b = Array('b', IntSort(), IntSort())
5006 >>> a = Map(f, b)
5007 >>> a
5008 Map(f, b)
5009 >>> is_map(a)
5010 True
5011 >>> is_map(b)
5012 False
5013 """
5014 return is_app_of(a, Z3_OP_ARRAY_MAP)
5015
5016

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

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

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

2986def is_mul(a : Any) -> bool:
2987 """Return `True` if `a` is an expression of the form b * c.
2988
2989 >>> x, y = Ints('x y')
2990 >>> is_mul(x * y)
2991 True
2992 >>> is_mul(x - y)
2993 False
2994 """
2995 return is_app_of(a, Z3_OP_MUL)
2996
2997

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

1817def is_not(a : Any) -> bool:
1818 """Return `True` if `a` is a Z3 not expression.
1819
1820 >>> p = Bool('p')
1821 >>> is_not(p)
1822 False
1823 >>> is_not(Not(p))
1824 True
1825 """
1826 return is_app_of(a, Z3_OP_NOT)
1827
1828

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

1793def is_or(a : Any) -> bool:
1794 """Return `True` if `a` is a Z3 or expression.
1795
1796 >>> p, q = Bools('p q')
1797 >>> is_or(Or(p, q))
1798 True
1799 >>> is_or(And(p, q))
1800 False
1801 """
1802 return is_app_of(a, Z3_OP_OR)
1803
1804

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

2094def is_pattern(a):
2095 """Return `True` if `a` is a Z3 pattern (hint for quantifier instantiation.
2096
2097 >>> f = Function('f', IntSort(), IntSort())
2098 >>> x = Int('x')
2099 >>> q = ForAll(x, f(x) == 0, patterns = [ f(x) ])
2100 >>> q
2101 ForAll(x, f(x) == 0)
2102 >>> q.num_patterns()
2103 1
2104 >>> is_pattern(q.pattern(0))
2105 True
2106 >>> q.pattern(0)
2107 f(Var(0))
2108 """
2109 return isinstance(a, PatternRef)
2110
2111

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

9593def is_probe(p):
9594 """Return `True` if `p` is a Z3 probe.
9595
9596 >>> is_probe(Int('x'))
9597 False
9598 >>> is_probe(Probe('memory'))
9599 True
9600 """
9601 return isinstance(p, Probe)
9602
9603

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

2344def is_quantifier(a):
2345 """Return `True` if `a` is a Z3 quantifier.
2346
2347 >>> f = Function('f', IntSort(), IntSort())
2348 >>> x = Int('x')
2349 >>> q = ForAll(x, f(x) == 0)
2350 >>> is_quantifier(q)
2351 True
2352 >>> is_quantifier(f(x))
2353 False
2354 """
2355 return isinstance(a, QuantifierRef)
2356
2357

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

2938def is_rational_value(a):
2939 """Return `True` if `a` is rational value of sort Real.
2940
2941 >>> is_rational_value(RealVal(1))
2942 True
2943 >>> is_rational_value(RealVal("3/5"))
2944 True
2945 >>> is_rational_value(IntVal(1))
2946 False
2947 >>> is_rational_value(1)
2948 False
2949 >>> n = Real('x') + 1
2950 >>> n.arg(1)
2951 1
2952 >>> is_rational_value(n.arg(1))
2953 True
2954 >>> is_rational_value(Real('x'))
2955 False
2956 """
2957 return is_arith(a) and a.is_real() and _is_numeral(a.ctx, a.as_ast())
2958
2959

◆ is_re()

is_re ( s)

Definition at line 12226 of file z3py.py.

12226def is_re(s):
12227 return isinstance(s, ReRef)
12228
12229

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

2887def is_real(a):
2888 """Return `True` if `a` is a real expression.
2889
2890 >>> x = Int('x')
2891 >>> is_real(x + 1)
2892 False
2893 >>> y = Real('y')
2894 >>> is_real(y)
2895 True
2896 >>> is_real(y + 1)
2897 True
2898 >>> is_real(1)
2899 False
2900 >>> is_real(RealVal(1))
2901 True
2902 """
2903 return is_arith(a) and a.is_real()
2904
2905

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

5250def is_select(a):
5251 """Return `True` if `a` is a Z3 array select application.
5252
5253 >>> a = Array('a', IntSort(), IntSort())
5254 >>> is_select(a)
5255 False
5256 >>> i = Int('i')
5257 >>> is_select(a[i])
5258 True
5259 """
5260 return is_app_of(a, Z3_OP_SELECT)
5261
5262

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

11898def is_seq(a):
11899 """Return `True` if `a` is a Z3 sequence expression.
11900 >>> print (is_seq(Unit(IntVal(0))))
11901 True
11902 >>> print (is_seq(StringVal("abc")))
11903 True
11904 """
11905 return isinstance(a, SeqRef)
11906
11907

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

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

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

5263def is_store(a):
5264 """Return `True` if `a` is a Z3 array store application.
5265
5266 >>> a = Array('a', IntSort(), IntSort())
5267 >>> is_store(a)
5268 False
5269 >>> is_store(Store(a, 0, 1))
5270 True
5271 """
5272 return is_app_of(a, Z3_OP_STORE)
5273

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

11908def is_string(a: Any) -> bool:
11909 """Return `True` if `a` is a Z3 string expression.
11910 >>> print (is_string(StringVal("ab")))
11911 True
11912 """
11913 return isinstance(a, SeqRef) and a.is_string()
11914
11915

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

11916def is_string_value(a: Any) -> bool:
11917 """return 'True' if 'a' is a Z3 string constant expression.
11918 >>> print (is_string_value(StringVal("a")))
11919 True
11920 >>> print (is_string_value(StringVal("a") + StringVal("b")))
11921 False
11922 """
11923 return isinstance(a, SeqRef) and a.is_string_value()
11924

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

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

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

3126def is_to_int(a : Any) -> bool:
3127 """Return `True` if `a` is an expression of the form ToInt(b).
3128
3129 >>> x = Real('x')
3130 >>> n = ToInt(x)
3131 >>> n
3132 ToInt(x)
3133 >>> is_to_int(n)
3134 True
3135 >>> is_to_int(x)
3136 False
3137 """
3138 return is_app_of(a, Z3_OP_TO_INT)
3139
3140

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

3111def is_to_real(a : Any) -> bool:
3112 """Return `True` if `a` is an expression of the form ToReal(b).
3113
3114 >>> x = Int('x')
3115 >>> n = ToReal(x)
3116 >>> n
3117 ToReal(x)
3118 >>> is_to_real(n)
3119 True
3120 >>> is_to_real(x)
3121 False
3122 """
3123 return is_app_of(a, Z3_OP_TO_REAL)
3124
3125

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

1749def is_true(a : Any) -> bool:
1750 """Return `True` if `a` is the Z3 true expression.
1751
1752 >>> p = Bool('p')
1753 >>> is_true(p)
1754 False
1755 >>> is_true(simplify(p == p))
1756 True
1757 >>> x = Real('x')
1758 >>> is_true(x == 0)
1759 False
1760 >>> # True is a Python Boolean expression
1761 >>> is_true(True)
1762 False
1763 """
1764 return is_app_of(a, Z3_OP_TRUE)
1765
1766

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

1440def is_var(a):
1441 """Return `True` if `a` is variable.
1442
1443 Z3 uses de-Bruijn indices for representing bound variables in
1444 quantifiers.
1445
1446 >>> x = Int('x')
1447 >>> is_var(x)
1448 False
1449 >>> is_const(x)
1450 True
1451 >>> f = Function('f', IntSort(), IntSort())
1452 >>> # Z3 replaces x with bound variables when ForAll is executed.
1453 >>> q = ForAll(x, f(x) == x)
1454 >>> b = q.body()
1455 >>> b
1456 f(Var(0)) == Var(0)
1457 >>> b.arg(1)
1458 Var(0)
1459 >>> is_var(b.arg(1))
1460 True
1461 """
1462 return is_expr(a) and _ast_kind(a.ctx, a) == Z3_VAR_AST
1463
1464

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

3677def IsInt(a):
3678 """ Return the Z3 predicate IsInt(a).
3679
3680 >>> x = Real('x')
3681 >>> IsInt(x + "1/2")
3682 IsInt(x + 1/2)
3683 >>> solve(IsInt(x + "1/2"), x > 0, x < 1)
3684 [x = 1/2]
3685 >>> solve(IsInt(x + "1/2"), x > 0, x < 1, x != "1/2")
3686 no solution
3687 """
3688 if z3_debug():
3689 _z3_assert(a.is_real(), "Z3 real expression expected.")
3690 ctx = a.ctx
3691 return BoolRef(Z3_mk_is_int(ctx.ref(), a.as_ast()), ctx)
3692
3693
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 5387 of file z3py.py.

5387def IsMember(e, s):
5388 """ Check if e is a member of set s
5389 >>> a = Const('a', SetSort(IntSort()))
5390 >>> IsMember(1, a)
5391 a[1]
5392 """
5393 ctx = _ctx_from_ast_arg_list([s, e])
5394 e = _py2expr(e, ctx)
5395 if is_finite_set(s):
5396 return FiniteSetIsMember(e, s)
5397 return BoolRef(Z3_mk_set_member(ctx.ref(), e.as_ast(), s.as_ast()), ctx)
5398
5399
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 5400 of file z3py.py.

5400def IsSubset(a, b):
5401 """ Check if a is a subset of b
5402 >>> a = Const('a', SetSort(IntSort()))
5403 >>> b = Const('b', SetSort(IntSort()))
5404 >>> IsSubset(a, b)
5405 subset(a, b)
5406 """
5407 ctx = _ctx_from_ast_arg_list([a, b])
5408 if is_finite_set(a):
5409 return FiniteSetIsSubset(a, b)
5410 return BoolRef(Z3_mk_set_subset(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
5411
5412
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 5198 of file z3py.py.

5198def K(dom, v):
5199 """Return a Z3 constant array expression.
5200
5201 >>> a = K(IntSort(), 10)
5202 >>> a
5203 K(Int, 10)
5204 >>> a.sort()
5205 Array(Int, Int)
5206 >>> i = Int('i')
5207 >>> a[i]
5208 K(Int, 10)[i]
5209 >>> simplify(a[i])
5210 10
5211 """
5212 if z3_debug():
5213 _z3_assert(is_sort(dom), "Z3 sort expected")
5214 ctx = dom.ctx
5215 if not is_expr(v):
5216 v = _py2expr(v, ctx)
5217 return ArrayRef(Z3_mk_const_array(ctx.ref(), dom.ast, v.as_ast()), ctx)
5218
5219
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 2432 of file z3py.py.

2432def Lambda(vs, body):
2433 """Create a Z3 lambda expression.
2434
2435 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2436 >>> mem0 = Array('mem0', IntSort(), IntSort())
2437 >>> lo, hi, e, i = Ints('lo hi e i')
2438 >>> mem1 = Lambda([i], If(And(lo <= i, i <= hi), e, mem0[i]))
2439 >>> mem1
2440 Lambda(i, If(And(lo <= i, i <= hi), e, mem0[i]))
2441 """
2442 ctx = body.ctx
2443 if is_app(vs):
2444 vs = [vs]
2445 num_vars = len(vs)
2446 _vs = (Ast * num_vars)()
2447 for i in range(num_vars):
2448 # TODO: Check if is constant
2449 _vs[i] = vs[i].as_ast()
2450 return QuantifierRef(Z3_mk_lambda_const(ctx.ref(), num_vars, _vs, body.as_ast()), ctx)
2451
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 12101 of file z3py.py.

12101def LastIndexOf(s, substr):
12102 """Retrieve the last index of substring within a string"""
12103 ctx = None
12104 ctx = _get_ctx2(s, substr, ctx)
12105 s = _coerce_seq(s, ctx)
12106 substr = _coerce_seq(substr, ctx)
12107 return ArithRef(Z3_mk_seq_last_index(s.ctx_ref(), s.as_ast(), substr.as_ast()), s.ctx)
12108
12109
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 12110 of file z3py.py.

12110def Length(s):
12111 """Obtain the length of a sequence 's'
12112 >>> l = Length(StringVal("abc"))
12113 >>> simplify(l)
12114 3
12115 """
12116 s = _coerce_seq(s)
12117 return ArithRef(Z3_mk_seq_length(s.ctx_ref(), s.as_ast()), s.ctx)
12118
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 12398 of file z3py.py.

12398def LinearOrder(a, index):
12399 return FuncDeclRef(Z3_mk_linear_order(a.ctx_ref(), a.ast, index), a.ctx)
12400
12401
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 12348 of file z3py.py.

12348def Loop(re, lo, hi=0):
12349 """Create the regular expression accepting between a lower and upper bound repetitions
12350 >>> re = Loop(Re("a"), 1, 3)
12351 >>> print(simplify(InRe("aa", re)))
12352 True
12353 >>> print(simplify(InRe("aaaa", re)))
12354 False
12355 >>> print(simplify(InRe("", re)))
12356 False
12357 """
12358 if z3_debug():
12359 _z3_assert(is_expr(re), "expression expected")
12360 return ReRef(Z3_mk_re_loop(re.ctx_ref(), re.as_ast(), lo, hi), re.ctx)
12361
12362
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 4610 of file z3py.py.

4610def LShR(a, b):
4611 """Create the Z3 expression logical right shift.
4612
4613 Use the operator >> for the arithmetical right shift.
4614
4615 >>> x, y = BitVecs('x y', 32)
4616 >>> LShR(x, y)
4617 LShR(x, y)
4618 >>> (x >> y).sexpr()
4619 '(bvashr x y)'
4620 >>> LShR(x, y).sexpr()
4621 '(bvlshr x y)'
4622 >>> BitVecVal(4, 3)
4623 4
4624 >>> BitVecVal(4, 3).as_signed_long()
4625 -4
4626 >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
4627 -2
4628 >>> simplify(BitVecVal(4, 3) >> 1)
4629 6
4630 >>> simplify(LShR(BitVecVal(4, 3), 1))
4631 2
4632 >>> simplify(BitVecVal(2, 3) >> 1)
4633 1
4634 >>> simplify(LShR(BitVecVal(2, 3), 1))
4635 1
4636 """
4637 _check_bv_args(a, b)
4638 a, b = _coerce_exprs(a, b)
4639 return BitVecRef(Z3_mk_bvlshr(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4640
4641
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 5175 of file z3py.py.

5175def Map(f, *args):
5176 """Return a Z3 map array expression.
5177
5178 >>> f = Function('f', IntSort(), IntSort(), IntSort())
5179 >>> a1 = Array('a1', IntSort(), IntSort())
5180 >>> a2 = Array('a2', IntSort(), IntSort())
5181 >>> b = Map(f, a1, a2)
5182 >>> b
5183 Map(f, a1, a2)
5184 >>> prove(b[0] == f(a1[0], a2[0]))
5185 proved
5186 """
5187 args = _get_args(args)
5188 if z3_debug():
5189 _z3_assert(len(args) > 0, "At least one Z3 array expression expected")
5190 _z3_assert(is_func_decl(f), "First argument must be a Z3 function declaration")
5191 _z3_assert(all([is_array(a) for a in args]), "Z3 array expected expected")
5192 _z3_assert(len(args) == f.arity(), "Number of arguments mismatch")
5193 _args, sz = _to_ast_array(args)
5194 ctx = f.ctx
5195 return ArrayRef(Z3_mk_map(ctx.ref(), f.ast, sz, _args), ctx)
5196
5197
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 1994 of file z3py.py.

1994def mk_not(a):
1995 if is_not(a):
1996 return a.arg(0)
1997 else:
1998 return Not(a)
1999
2000

◆ Model()

Model ( ctx = None,
eval = {} )

Definition at line 7470 of file z3py.py.

7470def Model(ctx=None, eval = {}):
7471 ctx = _get_ctx(ctx)
7472 mdl = ModelRef(Z3_mk_model(ctx.ref()), ctx)
7473 for k, v in eval.items():
7474 mdl.update_value(k, v)
7475 return mdl
7476
7477
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 2112 of file z3py.py.

2112def MultiPattern(*args):
2113 """Create a Z3 multi-pattern using the given expressions `*args`
2114
2115 >>> f = Function('f', IntSort(), IntSort())
2116 >>> g = Function('g', IntSort(), IntSort())
2117 >>> x = Int('x')
2118 >>> q = ForAll(x, f(x) != g(x), patterns = [ MultiPattern(f(x), g(x)) ])
2119 >>> q
2120 ForAll(x, f(x) != g(x))
2121 >>> q.num_patterns()
2122 1
2123 >>> is_pattern(q.pattern(0))
2124 True
2125 >>> q.pattern(0)
2126 MultiPattern(f(Var(0)), g(Var(0)))
2127 """
2128 if z3_debug():
2129 _z3_assert(len(args) > 0, "At least one argument expected")
2130 _z3_assert(all([is_expr(a) for a in args]), "Z3 expressions expected")
2131 ctx = args[0].ctx
2132 args, sz = _to_ast_array(args)
2133 return PatternRef(Z3_mk_pattern(ctx.ref(), sz, args), ctx)
2134
2135
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 1975 of file z3py.py.

1975def Not(a, ctx=None):
1976 """Create a Z3 not expression or probe.
1977
1978 >>> p = Bool('p')
1979 >>> Not(Not(p))
1980 Not(Not(p))
1981 >>> simplify(Not(Not(p)))
1982 p
1983 """
1984 ctx = _get_ctx(_ctx_from_ast_arg_list([a], ctx))
1985 if is_probe(a):
1986 # Not is also used to build probes
1987 return Probe(Z3_probe_not(ctx.ref(), a.probe), ctx)
1988 else:
1989 s = BoolSort(ctx)
1990 a = s.cast(a)
1991 return BoolRef(Z3_mk_not(ctx.ref(), a.as_ast()), ctx)
1992
1993
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 9067 of file z3py.py.

9067def num_simplifiers(ctx=None):
9068 """Return the number of simplifiers supported by the given context."""
9069 return Z3_get_num_simplifiers(_get_ctx(ctx).ref())
9070
9071
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 12438 of file z3py.py.

12438def on_clause_eh(ctx, p, n, dep, clause):
12439 onc = _my_hacky_class
12440 p = _to_expr_ref(to_Ast(p), onc.ctx)
12441 clause = AstVector(to_AstVectorObj(clause), onc.ctx)
12442 deps = [dep[i] for i in range(n)]
12443 onc.on_clause(p, deps, clause)
12444

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

12313def Option(re):
12314 """Create the regular expression that optionally accepts the argument.
12315 >>> re = Option(Re("a"))
12316 >>> print(simplify(InRe("a", re)))
12317 True
12318 >>> print(simplify(InRe("", re)))
12319 True
12320 >>> print(simplify(InRe("aa", re)))
12321 False
12322 """
12323 if z3_debug():
12324 _z3_assert(is_expr(re), "expression expected")
12325 return ReRef(Z3_mk_re_option(re.ctx_ref(), re.as_ast()), re.ctx)
12326
12327
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 2042 of file z3py.py.

2042def Or(*args):
2043 """Create a Z3 or-expression or or-probe.
2044
2045 >>> p, q, r = Bools('p q r')
2046 >>> Or(p, q, r)
2047 Or(p, q, r)
2048 >>> P = BoolVector('p', 5)
2049 >>> Or(P)
2050 Or(p__0, p__1, p__2, p__3, p__4)
2051 """
2052 last_arg = None
2053 if len(args) > 0:
2054 last_arg = args[len(args) - 1]
2055 if isinstance(last_arg, Context):
2056 ctx = args[len(args) - 1]
2057 args = args[:len(args) - 1]
2058 elif len(args) == 1 and isinstance(args[0], AstVector):
2059 ctx = args[0].ctx
2060 args = [a for a in args[0]]
2061 else:
2062 ctx = None
2063 args = _get_args(args)
2064 ctx = _get_ctx(_ctx_from_ast_arg_list(args, ctx))
2065 if z3_debug():
2066 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression or probe")
2067 if _has_probe(args):
2068 return _probe_or(args, ctx)
2069 else:
2070 args = _coerce_expr_list(args, ctx)
2071 _args, sz = _to_ast_array(args)
2072 return BoolRef(Z3_mk_or(ctx.ref(), sz, _args), ctx)
2073
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 9286 of file z3py.py.

9286def OrElse(*ts, **ks):
9287 """Return a tactic that applies the tactics in `*ts` until one of them succeeds (it doesn't fail).
9288
9289 >>> x = Int('x')
9290 >>> t = OrElse(Tactic('split-clause'), Tactic('skip'))
9291 >>> # Tactic split-clause fails if there is no clause in the given goal.
9292 >>> t(x == 0)
9293 [[x == 0]]
9294 >>> t(Or(x == 0, x == 1))
9295 [[x == 0], [x == 1]]
9296 """
9297 if z3_debug():
9298 _z3_assert(len(ts) >= 2, "At least two arguments expected")
9299 ctx = ks.get("ctx", None)
9300 num = len(ts)
9301 r = ts[0]
9302 for i in range(num - 1):
9303 r = _or_else(r, ts[i + 1], ctx)
9304 return r
9305
9306

◆ ParAndThen()

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

Definition at line 9342 of file z3py.py.

9342def ParAndThen(t1, t2, ctx=None):
9343 """Alias for ParThen(t1, t2, ctx)."""
9344 return ParThen(t1, t2, ctx)
9345
9346

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

9307def ParOr(*ts, **ks):
9308 """Return a tactic that applies the tactics in `*ts` in parallel until one of them succeeds (it doesn't fail).
9309
9310 >>> x = Int('x')
9311 >>> t = ParOr(Tactic('simplify'), Tactic('fail'))
9312 >>> t(x + 1 == 2)
9313 [[x == 1]]
9314 """
9315 if z3_debug():
9316 _z3_assert(len(ts) >= 2, "At least two arguments expected")
9317 ctx = _get_ctx(ks.get("ctx", None))
9318 ts = [_to_tactic(t, ctx) for t in ts]
9319 sz = len(ts)
9320 _args = (TacticObj * sz)()
9321 for i in range(sz):
9322 _args[i] = ts[i].tactic
9323 return Tactic(Z3_tactic_par_or(ctx.ref(), sz, _args), ctx)
9324
9325
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 10222 of file z3py.py.

10222def parse_smt2_file(f, sorts={}, decls={}, ctx=None):
10223 """Parse a file in SMT 2.0 format using the given sorts and decls.
10224
10225 This function is similar to parse_smt2_string().
10226 """
10227 ctx = _get_ctx(ctx)
10228 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
10229 dsz, dnames, ddecls = _dict2darray(decls, ctx)
10230 return AstVector(Z3_parse_smtlib2_file(ctx.ref(), f, ssz, snames, ssorts, dsz, dnames, ddecls), ctx)
10231
10232
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 10201 of file z3py.py.

10201def parse_smt2_string(s, sorts={}, decls={}, ctx=None):
10202 """Parse a string in SMT 2.0 format using the given sorts and decls.
10203
10204 The arguments sorts and decls are Python dictionaries used to initialize
10205 the symbol table used for the SMT 2.0 parser.
10206
10207 >>> parse_smt2_string('(declare-const x Int) (assert (> x 0)) (assert (< x 10))')
10208 [x > 0, x < 10]
10209 >>> x, y = Ints('x y')
10210 >>> f = Function('f', IntSort(), IntSort())
10211 >>> parse_smt2_string('(assert (> (+ foo (g bar)) 0))', decls={ 'foo' : x, 'bar' : y, 'g' : f})
10212 [x + f(y) > 0]
10213 >>> parse_smt2_string('(declare-const a U) (assert (> a 0))', sorts={ 'U' : IntSort() })
10214 [a > 0]
10215 """
10216 ctx = _get_ctx(ctx)
10217 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
10218 dsz, dnames, ddecls = _dict2darray(decls, ctx)
10219 return AstVector(Z3_parse_smtlib2_string(ctx.ref(), s, ssz, snames, ssorts, dsz, dnames, ddecls), ctx)
10220
10221
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 9326 of file z3py.py.

9326def ParThen(t1, t2, ctx=None):
9327 """Return a tactic that applies t1 and then t2 to every subgoal produced by t1.
9328 The subgoals are processed in parallel.
9329
9330 >>> x, y = Ints('x y')
9331 >>> t = ParThen(Tactic('split-clause'), Tactic('propagate-values'))
9332 >>> t(And(Or(x == 1, x == 2), y == x + 1))
9333 [[x == 1, y == 2], [x == 2, y == 3]]
9334 """
9335 t1 = _to_tactic(t1, ctx)
9336 t2 = _to_tactic(t2, ctx)
9337 if z3_debug():
9338 _z3_assert(t1.ctx == t2.ctx, "Context mismatch")
9339 return Tactic(Z3_tactic_par_and_then(t1.ctx.ref(), t1.tactic, t2.tactic), t1.ctx)
9340
9341
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 12394 of file z3py.py.

12394def PartialOrder(a, index):
12395 return FuncDeclRef(Z3_mk_partial_order(a.ctx_ref(), a.ast, index), a.ctx)
12396
12397
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 9978 of file z3py.py.

9978def PbEq(args, k, ctx=None):
9979 """Create a Pseudo-Boolean equality k constraint.
9980
9981 >>> a, b, c = Bools('a b c')
9982 >>> f = PbEq(((a,1),(b,3),(c,2)), 3)
9983 """
9984 _z3_check_cint_overflow(k, "k")
9985 ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
9986 return BoolRef(Z3_mk_pbeq(ctx.ref(), sz, _args, _coeffs, k), ctx)
9987
9988
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 9967 of file z3py.py.

9967def PbGe(args, k):
9968 """Create a Pseudo-Boolean inequality k constraint.
9969
9970 >>> a, b, c = Bools('a b c')
9971 >>> f = PbGe(((a,1),(b,3),(c,2)), 3)
9972 """
9973 _z3_check_cint_overflow(k, "k")
9974 ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
9975 return BoolRef(Z3_mk_pbge(ctx.ref(), sz, _args, _coeffs, k), ctx)
9976
9977
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 9956 of file z3py.py.

9956def PbLe(args, k):
9957 """Create a Pseudo-Boolean inequality k constraint.
9958
9959 >>> a, b, c = Bools('a b c')
9960 >>> f = PbLe(((a,1),(b,3),(c,2)), 3)
9961 """
9962 _z3_check_cint_overflow(k, "k")
9963 ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
9964 return BoolRef(Z3_mk_pble(ctx.ref(), sz, _args, _coeffs, k), ctx)
9965
9966
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 12406 of file z3py.py.

12406def PiecewiseLinearOrder(a, index):
12407 return FuncDeclRef(Z3_mk_piecewise_linear_order(a.ctx_ref(), a.ast, index), a.ctx)
12408
12409
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 12298 of file z3py.py.

12298def Plus(re):
12299 """Create the regular expression accepting one or more repetitions of argument.
12300 >>> re = Plus(Re("a"))
12301 >>> print(simplify(InRe("aa", re)))
12302 True
12303 >>> print(simplify(InRe("ab", re)))
12304 False
12305 >>> print(simplify(InRe("", re)))
12306 False
12307 """
12308 if z3_debug():
12309 _z3_assert(is_expr(re), "expression expected")
12310 return ReRef(Z3_mk_re_plus(re.ctx_ref(), re.as_ast()), re.ctx)
12311
12312
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 12017 of file z3py.py.

12017def PrefixOf(a, b):
12018 """Check if 'a' is a prefix of 'b'
12019 >>> s1 = PrefixOf("ab", "abc")
12020 >>> simplify(s1)
12021 True
12022 >>> s2 = PrefixOf("bc", "abc")
12023 >>> simplify(s2)
12024 False
12025 """
12026 ctx = _get_ctx2(a, b)
12027 a = _coerce_seq(a, ctx)
12028 b = _coerce_seq(b, ctx)
12029 return BoolRef(Z3_mk_seq_prefix(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
12030
12031
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 9622 of file z3py.py.

9622def probe_description(name, ctx=None):
9623 """Return a short description for the probe named `name`.
9624
9625 >>> d = probe_description('memory')
9626 """
9627 ctx = _get_ctx(ctx)
9628 return Z3_probe_get_descr(ctx.ref(), name)
9629
9630
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 9611 of file z3py.py.

9611def probes(ctx=None):
9612 """Return a list of all available probes in Z3.
9613
9614 >>> l = probes()
9615 >>> l.count('memory') == 1
9616 True
9617 """
9618 ctx = _get_ctx(ctx)
9619 return [Z3_get_probe_name(ctx.ref(), i) for i in range(Z3_get_num_probes(ctx.ref()))]
9620
9621
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 9863 of file z3py.py.

9863def Product(*args):
9864 """Create the product of the Z3 expressions.
9865
9866 >>> a, b, c = Ints('a b c')
9867 >>> Product(a, b, c)
9868 a*b*c
9869 >>> Product([a, b, c])
9870 a*b*c
9871 >>> A = IntVector('a', 5)
9872 >>> Product(A)
9873 a__0*a__1*a__2*a__3*a__4
9874 """
9875 args = _get_args(args)
9876 if len(args) == 0:
9877 return 1
9878 ctx = _ctx_from_ast_arg_list(args)
9879 if ctx is None:
9880 return _reduce(lambda a, b: a * b, args, 1)
9881 args = _coerce_expr_list(args, ctx)
9882 if is_bv(args[0]) or isinstance(args[0], FiniteFieldRef):
9883 return _reduce(lambda a, b: a * b, args, 1)
9884 else:
9885 _args, sz = _to_ast_array(args)
9886 return _to_expr_ref(Z3_mk_mul(ctx.ref(), sz, _args), ctx)
9887
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 12603 of file z3py.py.

12603def PropagateFunction(name, *sig):
12604 """Create a function that gets tracked by user propagator.
12605 Every term headed by this function symbol is tracked.
12606 If a term is fixed and the fixed callback is registered a
12607 callback is invoked that the term headed by this function is fixed.
12608 """
12609 sig = _get_args(sig)
12610 if z3_debug():
12611 _z3_assert(len(sig) > 0, "At least two arguments expected")
12612 arity = len(sig) - 1
12613 rng = sig[arity]
12614 if z3_debug():
12615 _z3_assert(is_sort(rng), "Z3 sort expected")
12616 dom = (Sort * arity)()
12617 for i in range(arity):
12618 if z3_debug():
12619 _z3_assert(is_sort(sig[i]), "Z3 sort expected")
12620 dom[i] = sig[i].ast
12621 ctx = rng.ctx
12622 return FuncDeclRef(Z3_solver_propagate_declare(ctx.ref(), to_symbol(name, ctx), arity, dom, rng.ast), ctx)
12623
12624
12625
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 10050 of file z3py.py.

10050def prove(claim, show=False, **keywords):
10051 """Try to prove the given claim.
10052
10053 This is a simple function for creating demonstrations. It tries to prove
10054 `claim` by showing the negation is unsatisfiable.
10055
10056 >>> p, q = Bools('p q')
10057 >>> prove(Not(And(p, q)) == Or(Not(p), Not(q)))
10058 proved
10059 """
10060 if z3_debug():
10061 _z3_assert(is_bool(claim), "Z3 Boolean expression expected")
10062 s = Solver()
10063 s.set(**keywords)
10064 s.add(Not(claim))
10065 if show:
10066 print(s)
10067 r = s.check()
10068 if r == unsat:
10069 print("proved")
10070 elif r == unknown:
10071 print("failed to prove")
10072 print(s.model())
10073 else:
10074 print("counterexample")
10075 print(s.model())
10076
10077

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

3516def Q(a, b, ctx=None):
3517 """Return a Z3 rational a/b.
3518
3519 If `ctx=None`, then the global context is used.
3520
3521 >>> Q(3,5)
3522 3/5
3523 >>> Q(3,5).sort()
3524 Real
3525 """
3526 return simplify(RatVal(a, b, ctx=ctx))
3527
3528

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

12363def Range(lo, hi, ctx=None):
12364 """Create the range regular expression over two sequences of length 1
12365 >>> range = Range("a","z")
12366 >>> print(simplify(InRe("b", range)))
12367 True
12368 >>> print(simplify(InRe("bb", range)))
12369 False
12370 """
12371 lo = _coerce_seq(lo, ctx)
12372 hi = _coerce_seq(hi, ctx)
12373 if z3_debug():
12374 _z3_assert(is_expr(lo), "expression expected")
12375 _z3_assert(is_expr(hi), "expression expected")
12376 return ReRef(Z3_mk_re_range(lo.ctx_ref(), lo.ast, hi.ast), lo.ctx)
12377
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 3496 of file z3py.py.

3496def RatVal(a, b, ctx=None):
3497 """Return a Z3 rational a/b.
3498
3499 If `ctx=None`, then the global context is used.
3500
3501 Note: Division by zero (b == 0) is allowed in Z3 symbolic expressions.
3502 Z3 can reason about such expressions symbolically.
3503
3504 >>> RatVal(3,5)
3505 3/5
3506 >>> RatVal(3,5).sort()
3507 Real
3508 """
3509 if z3_debug():
3510 _z3_assert(_is_int(a) or isinstance(a, str), "First argument cannot be converted into an integer")
3511 _z3_assert(_is_int(b) or isinstance(b, str), "Second argument cannot be converted into an integer")
3512 # Division by 0 is intentionally allowed - Z3 handles it symbolically
3513 return simplify(RealVal(a, ctx) / RealVal(b, ctx))
3514
3515

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

12191def Re(s, ctx=None):
12192 """The regular expression that accepts sequence 's'
12193 >>> s1 = Re("ab")
12194 >>> s2 = Re(StringVal("ab"))
12195 >>> s3 = Re(Unit(BoolVal(True)))
12196 """
12197 s = _coerce_seq(s, ctx)
12198 return ReRef(Z3_mk_seq_to_re(s.ctx_ref(), s.as_ast()), s.ctx)
12199
12200
12201# Regular expressions
12202
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 3582 of file z3py.py.

3582def Real(name, ctx=None):
3583 """Return a real constant named `name`. If `ctx=None`, then the global context is used.
3584
3585 >>> x = Real('x')
3586 >>> is_real(x)
3587 True
3588 >>> is_real(x + 1)
3589 True
3590 """
3591 ctx = _get_ctx(ctx)
3592 return ArithRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), RealSort(ctx).ast), ctx)
3593
3594

Referenced by Reals(), and RealVector().

◆ RealPart()

RealPart ( value)
Return the Real-valued real component of a Complex expression.

Definition at line 3390 of file z3py.py.

3390def RealPart(value):
3391 """Return the Real-valued real component of a Complex expression."""
3392 _z3_assert(is_complex(value), "Complex expression expected")
3393 return _to_expr_ref(Z3_mk_real_part(value.ctx_ref(), value.as_ast()), value.ctx)
3394
3395
Z3_ast Z3_API Z3_mk_real_part(Z3_context c, Z3_ast z)
Return the real component of a Complex expression.

Referenced by ComplexRef.real_part().

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

3595def Reals(names, ctx=None):
3596 """Return a tuple of real constants.
3597
3598 >>> x, y, z = Reals('x y z')
3599 >>> Sum(x, y, z)
3600 x + y + z
3601 >>> Sum(x, y, z).sort()
3602 Real
3603 """
3604 ctx = _get_ctx(ctx)
3605 if isinstance(names, str):
3606 names = names.split(" ")
3607 return [Real(name, ctx) for name in names]
3608
3609

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

3436def RealSort(ctx=None):
3437 """Return the real sort in the given context. If `ctx=None`, then the global context is used.
3438
3439 >>> RealSort()
3440 Real
3441 >>> x = Const('x', RealSort())
3442 >>> is_real(x)
3443 True
3444 >>> is_int(x)
3445 False
3446 >>> x.sort() == RealSort()
3447 True
3448 """
3449 ctx = _get_ctx(ctx)
3450 return ArithSortRef(Z3_mk_real_sort(ctx.ref()), ctx)
3451
3452
Z3_sort Z3_API Z3_mk_real_sort(Z3_context c)
Create the real type.

Referenced by ComplexVal(), FreshReal(), Real(), 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 3477 of file z3py.py.

3477def RealVal(val, ctx=None):
3478 """Return a Z3 real value.
3479
3480 `val` may be a Python int, long, float or string representing a number in decimal or rational notation.
3481 If `ctx=None`, then the global context is used.
3482
3483 >>> RealVal(1)
3484 1
3485 >>> RealVal(1).sort()
3486 Real
3487 >>> RealVal("3/5")
3488 3/5
3489 >>> RealVal("1.5")
3490 3/2
3491 """
3492 ctx = _get_ctx(ctx)
3493 return RatNumRef(Z3_mk_numeral(ctx.ref(), str(val), Z3_mk_real_sort(ctx.ref())), ctx)
3494
3495

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

1617def RealVar(idx: int, ctx=None) -> ExprRef:
1618 """
1619 Create a real free variable. Free variables are used to create quantified formulas.
1620 They are also used to create polynomials.
1621
1622 >>> RealVar(0)
1623 Var(0)
1624 """
1625 return Var(idx, RealSort(ctx))
1626

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

1627def RealVarVector(n: int, ctx= None):
1628 """
1629 Create a list of Real free variables.
1630 The variables have ids: 0, 1, ..., n-1
1631
1632 >>> x0, x1, x2, x3 = RealVarVector(4)
1633 >>> x2
1634 Var(2)
1635 """
1636 return [RealVar(i, ctx) for i in range(n)]
1637

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

3610def RealVector(prefix, sz, ctx=None):
3611 """Return a list of real constants of size `sz`.
3612
3613 >>> X = RealVector('x', 3)
3614 >>> X
3615 [x__0, x__1, x__2]
3616 >>> Sum(X)
3617 x__0 + x__1 + x__2
3618 >>> Sum(X).sort()
3619 Real
3620 """
3621 ctx = _get_ctx(ctx)
3622 return [Real("%s__%s" % (prefix, i), ctx) for i in range(sz)]
3623
3624

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

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

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

9375def Repeat(t, max=4294967295, ctx=None):
9376 """Return a tactic that keeps applying `t` until the goal is not modified anymore
9377 or the maximum number of iterations `max` is reached.
9378
9379 >>> x, y = Ints('x y')
9380 >>> c = And(Or(x == 0, x == 1), Or(y == 0, y == 1), x > y)
9381 >>> t = Repeat(OrElse(Tactic('split-clause'), Tactic('skip')))
9382 >>> r = t(c)
9383 >>> for subgoal in r: print(subgoal)
9384 [x == 0, y == 0, x > y]
9385 [x == 0, y == 1, x > y]
9386 [x == 1, y == 0, x > y]
9387 [x == 1, y == 1, x > y]
9388 >>> t = Then(t, Tactic('propagate-values'))
9389 >>> t(c)
9390 [[x == 1, y == 0]]
9391 """
9392 t = _to_tactic(t, ctx)
9393 return Tactic(Z3_tactic_repeat(t.ctx.ref(), t.tactic, max), t.ctx)
9394
9395
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 4732 of file z3py.py.

4732def RepeatBitVec(n, a):
4733 """Return an expression representing `n` copies of `a`.
4734
4735 >>> x = BitVec('x', 8)
4736 >>> n = RepeatBitVec(4, x)
4737 >>> n
4738 RepeatBitVec(4, x)
4739 >>> n.size()
4740 32
4741 >>> v0 = BitVecVal(10, 4)
4742 >>> print("%.x" % v0.as_long())
4743 a
4744 >>> v = simplify(RepeatBitVec(4, v0))
4745 >>> v.size()
4746 16
4747 >>> print("%.x" % v.as_long())
4748 aaaa
4749 """
4750 if z3_debug():
4751 _z3_assert(_is_int(n), "First argument must be an integer")
4752 _z3_assert(is_bv(a), "Second argument must be a Z3 bit-vector expression")
4753 return BitVecRef(Z3_mk_repeat(a.ctx_ref(), n, a.as_ast()), a.ctx)
4754
4755
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 12066 of file z3py.py.

12066def Replace(s, src, dst):
12067 """Replace the first occurrence of 'src' by 'dst' in 's'
12068 >>> r = Replace("aaa", "a", "b")
12069 >>> simplify(r)
12070 "baa"
12071 """
12072 ctx = _get_ctx2(dst, s)
12073 if ctx is None and is_expr(src):
12074 ctx = src.ctx
12075 src = _coerce_seq(src, ctx)
12076 dst = _coerce_seq(dst, ctx)
12077 s = _coerce_seq(s, ctx)
12078 return SeqRef(Z3_mk_seq_replace(src.ctx_ref(), s.as_ast(), src.as_ast(), dst.as_ast()), s.ctx)
12079
12080
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 12210 of file z3py.py.

12210def ReSort(s):
12211 if is_ast(s):
12212 return ReSortRef(Z3_mk_re_sort(s.ctx.ref(), s.ast), s.ctx)
12213 if s is None or isinstance(s, Context):
12214 ctx = _get_ctx(s)
12215 return ReSortRef(Z3_mk_re_sort(ctx.ref(), Z3_mk_string_sort(ctx.ref())), s.ctx)
12216 raise Z3Exception("Regular expression sort constructor expects either a string or a context or no argument")
12217
12218
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 10637 of file z3py.py.

10637def RNA(ctx=None):
10638 ctx = _get_ctx(ctx)
10639 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_away(ctx.ref()), ctx)
10640
10641
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 10627 of file z3py.py.

10627def RNE(ctx=None):
10628 ctx = _get_ctx(ctx)
10629 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_even(ctx.ref()), ctx)
10630
10631
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 4642 of file z3py.py.

4642def RotateLeft(a, b):
4643 """Return an expression representing `a` rotated to the left `b` times.
4644
4645 >>> a, b = BitVecs('a b', 16)
4646 >>> RotateLeft(a, b)
4647 RotateLeft(a, b)
4648 >>> simplify(RotateLeft(a, 0))
4649 a
4650 >>> simplify(RotateLeft(a, 16))
4651 a
4652 """
4653 _check_bv_args(a, b)
4654 a, b = _coerce_exprs(a, b)
4655 return BitVecRef(Z3_mk_ext_rotate_left(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4656
4657
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 4658 of file z3py.py.

4658def RotateRight(a, b):
4659 """Return an expression representing `a` rotated to the right `b` times.
4660
4661 >>> a, b = BitVecs('a b', 16)
4662 >>> RotateRight(a, b)
4663 RotateRight(a, b)
4664 >>> simplify(RotateRight(a, 0))
4665 a
4666 >>> simplify(RotateRight(a, 16))
4667 a
4668 """
4669 _check_bv_args(a, b)
4670 a, b = _coerce_exprs(a, b)
4671 return BitVecRef(Z3_mk_ext_rotate_right(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4672
4673
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 10632 of file z3py.py.

10632def RoundNearestTiesToAway(ctx=None):
10633 ctx = _get_ctx(ctx)
10634 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_away(ctx.ref()), ctx)
10635
10636

◆ RoundNearestTiesToEven()

RoundNearestTiesToEven ( ctx = None)

Definition at line 10622 of file z3py.py.

10622def RoundNearestTiesToEven(ctx=None):
10623 ctx = _get_ctx(ctx)
10624 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_even(ctx.ref()), ctx)
10625
10626

◆ RoundTowardNegative()

RoundTowardNegative ( ctx = None)

Definition at line 10652 of file z3py.py.

10652def RoundTowardNegative(ctx=None):
10653 ctx = _get_ctx(ctx)
10654 return FPRMRef(Z3_mk_fpa_round_toward_negative(ctx.ref()), ctx)
10655
10656
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 10642 of file z3py.py.

10642def RoundTowardPositive(ctx=None):
10643 ctx = _get_ctx(ctx)
10644 return FPRMRef(Z3_mk_fpa_round_toward_positive(ctx.ref()), ctx)
10645
10646
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 10662 of file z3py.py.

10662def RoundTowardZero(ctx=None):
10663 ctx = _get_ctx(ctx)
10664 return FPRMRef(Z3_mk_fpa_round_toward_zero(ctx.ref()), ctx)
10665
10666
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 10657 of file z3py.py.

10657def RTN(ctx=None):
10658 ctx = _get_ctx(ctx)
10659 return FPRMRef(Z3_mk_fpa_round_toward_negative(ctx.ref()), ctx)
10660
10661

◆ RTP()

RTP ( ctx = None)

Definition at line 10647 of file z3py.py.

10647def RTP(ctx=None):
10648 ctx = _get_ctx(ctx)
10649 return FPRMRef(Z3_mk_fpa_round_toward_positive(ctx.ref()), ctx)
10650
10651

◆ RTZ()

RTZ ( ctx = None)

Definition at line 10667 of file z3py.py.

10667def RTZ(ctx=None):
10668 ctx = _get_ctx(ctx)
10669 return FPRMRef(Z3_mk_fpa_round_toward_zero(ctx.ref()), ctx)
10670
10671

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

5159def Select(a, *args):
5160 """Return a Z3 select array expression.
5161
5162 >>> a = Array('a', IntSort(), IntSort())
5163 >>> i = Int('i')
5164 >>> Select(a, i)
5165 a[i]
5166 >>> eq(Select(a, i), a[i])
5167 True
5168 """
5169 args = _get_args(args)
5170 if z3_debug():
5171 _z3_assert(is_array_sort(a), "First argument must be a Z3 array expression")
5172 return a[args]
5173
5174

◆ SeqFoldLeft()

SeqFoldLeft ( f,
a,
s )

Definition at line 12143 of file z3py.py.

12143def SeqFoldLeft(f, a, s):
12144 ctx = _get_ctx2(f, s)
12145 s = _coerce_seq(s, ctx)
12146 a = _py2expr(a)
12147 return _to_expr_ref(Z3_mk_seq_foldl(s.ctx_ref(), f.as_ast(), a.as_ast(), s.as_ast()), ctx)
12148
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 12149 of file z3py.py.

12149def SeqFoldLeftI(f, i, a, s):
12150 ctx = _get_ctx2(f, s)
12151 s = _coerce_seq(s, ctx)
12152 a = _py2expr(a)
12153 i = _py2expr(i)
12154 return _to_expr_ref(Z3_mk_seq_foldli(s.ctx_ref(), f.as_ast(), i.as_ast(), a.as_ast(), s.as_ast()), ctx)
12155
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 12129 of file z3py.py.

12129def SeqMap(f, s):
12130 """Map function 'f' over sequence 's'"""
12131 ctx = _get_ctx2(f, s)
12132 s = _coerce_seq(s, ctx)
12133 return _to_expr_ref(Z3_mk_seq_map(s.ctx_ref(), f.as_ast(), s.as_ast()), ctx)
12134
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 12135 of file z3py.py.

12135def SeqMapI(f, i, s):
12136 """Map function 'f' over sequence 's' at index 'i'"""
12137 ctx = _get_ctx2(f, s)
12138 s = _coerce_seq(s, ctx)
12139 if not is_expr(i):
12140 i = _py2expr(i)
12141 return _to_expr_ref(Z3_mk_seq_mapi(s.ctx_ref(), f.as_ast(), i.as_ast(), s.as_ast()), ctx)
12142
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 12119 of file z3py.py.

12119def SeqPower(s, n):
12120 """Concatenate the sequence 's' with itself 'n' times. It is the empty sequence for n <= 0
12121 >>> p = SeqPower(StringVal("ab"), 2)
12122 >>> simplify(p)
12123 "abab"
12124 """
12125 s = _coerce_seq(s)
12126 n = _py2expr(n, s.ctx)
12127 return SeqRef(Z3_mk_seq_power(s.ctx_ref(), s.as_ast(), n.as_ast()), s.ctx)
12128
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 11763 of file z3py.py.

11763def SeqSort(s):
11764 """Create a sequence sort over elements provided in the argument
11765 >>> s = SeqSort(IntSort())
11766 >>> s == Unit(IntVal(1)).sort()
11767 True
11768 """
11769 return SeqSortRef(Z3_mk_seq_sort(s.ctx_ref(), s.ast), s.ctx)
11770
11771
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 10283 of file z3py.py.

10283def set_default_fp_sort(ebits, sbits, ctx=None):
10284 global _dflt_fpsort_ebits
10285 global _dflt_fpsort_sbits
10286 _dflt_fpsort_ebits = ebits
10287 _dflt_fpsort_sbits = sbits
10288
10289

◆ set_default_rounding_mode()

set_default_rounding_mode ( rm,
ctx = None )

Definition at line 10270 of file z3py.py.

10270def set_default_rounding_mode(rm, ctx=None):
10271 global _dflt_rounding_mode
10272 if is_fprm_value(rm):
10273 _dflt_rounding_mode = rm.kind()
10274 else:
10275 _z3_assert(_dflt_rounding_mode in _ROUNDING_MODES, "illegal rounding mode")
10276 _dflt_rounding_mode = rm
10277
10278

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

5338def SetAdd(s, e):
5339 """ Add element e to set s
5340 >>> a = Const('a', SetSort(IntSort()))
5341 >>> SetAdd(a, 1)
5342 Store(a, 1, True)
5343 """
5344 ctx = _ctx_from_ast_arg_list([s, e])
5345 e = _py2expr(e, ctx)
5346 if is_finite_set(s):
5347 return FiniteSetSingleton(e) | s
5348 return ArrayRef(Z3_mk_set_add(ctx.ref(), s.as_ast(), e.as_ast()), ctx)
5349
5350
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 5364 of file z3py.py.

5364def SetComplement(s):
5365 """ The complement of set s
5366 >>> a = Const('a', SetSort(IntSort()))
5367 >>> SetComplement(a)
5368 complement(a)
5369 """
5370 ctx = s.ctx
5371 return ArrayRef(Z3_mk_set_complement(ctx.ref(), s.as_ast()), ctx)
5372
5373
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 5351 of file z3py.py.

5351def SetDel(s, e):
5352 """ Remove element e to set s
5353 >>> a = Const('a', SetSort(IntSort()))
5354 >>> SetDel(a, 1)
5355 Store(a, 1, False)
5356 """
5357 ctx = _ctx_from_ast_arg_list([s, e])
5358 e = _py2expr(e, ctx)
5359 if is_finite_set(s):
5360 return s - FiniteSetSingleton(e)
5361 return ArrayRef(Z3_mk_set_del(ctx.ref(), s.as_ast(), e.as_ast()), ctx)
5362
5363
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 5374 of file z3py.py.

5374def SetDifference(a, b):
5375 """ The set difference of a and b
5376 >>> a = Const('a', SetSort(IntSort()))
5377 >>> b = Const('b', SetSort(IntSort()))
5378 >>> SetDifference(a, b)
5379 setminus(a, b)
5380 """
5381 ctx = _ctx_from_ast_arg_list([a, b])
5382 if is_finite_set(a):
5383 return FiniteSetDifference(a, b)
5384 return ArrayRef(Z3_mk_set_difference(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
5385
5386
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 5322 of file z3py.py.

5322def SetIntersect(*args):
5323 """ Take the union of sets
5324 >>> a = Const('a', SetSort(IntSort()))
5325 >>> b = Const('b', SetSort(IntSort()))
5326 >>> SetIntersect(a, b)
5327 intersection(a, b)
5328 """
5329 args = _get_args(args)
5330 ctx = _ctx_from_ast_arg_list(args)
5331 if len(args) > 0 and is_finite_set(args[0]):
5332 from functools import reduce
5333 return reduce(FiniteSetIntersect, args)
5334 _args, sz = _to_ast_array(args)
5335 return ArrayRef(Z3_mk_set_intersect(ctx.ref(), sz, _args), ctx)
5336
5337
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 5281 of file z3py.py.

5281def SetSort(s):
5282 """ Create a set sort over element sort s"""
5283 return ArraySort(s, BoolSort())
5284
5285

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

5306def SetUnion(*args):
5307 """ Take the union of sets
5308 >>> a = Const('a', SetSort(IntSort()))
5309 >>> b = Const('b', SetSort(IntSort()))
5310 >>> SetUnion(a, b)
5311 union(a, b)
5312 """
5313 args = _get_args(args)
5314 if len(args) > 0 and is_finite_set(args[0]):
5315 from functools import reduce
5316 return reduce(FiniteSetUnion, args)
5317 ctx = _ctx_from_ast_arg_list(args)
5318 _args, sz = _to_ast_array(args)
5319 return ArrayRef(Z3_mk_set_union(ctx.ref(), sz, _args), ctx)
5320
5321
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 4674 of file z3py.py.

4674def SignExt(n, a):
4675 """Return a bit-vector expression with `n` extra sign-bits.
4676
4677 >>> x = BitVec('x', 16)
4678 >>> n = SignExt(8, x)
4679 >>> n.size()
4680 24
4681 >>> n
4682 SignExt(8, x)
4683 >>> n.sort()
4684 BitVec(24)
4685 >>> v0 = BitVecVal(2, 2)
4686 >>> v0
4687 2
4688 >>> v0.size()
4689 2
4690 >>> v = simplify(SignExt(6, v0))
4691 >>> v
4692 254
4693 >>> v.size()
4694 8
4695 >>> print("%.x" % v.as_long())
4696 fe
4697 """
4698 if z3_debug():
4699 _z3_assert(_is_int(n), "First argument must be an integer")
4700 _z3_assert(is_bv(a), "Second argument must be a Z3 bit-vector expression")
4701 return BitVecRef(Z3_mk_sign_ext(a.ctx_ref(), n, a.as_ast()), a.ctx)
4702
4703
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 8269 of file z3py.py.

8269def SimpleSolver(ctx=None, logFile=None):
8270 """Return a simple general purpose solver with limited amount of preprocessing.
8271
8272 >>> s = SimpleSolver()
8273 >>> x = Int('x')
8274 >>> s.add(x > 0)
8275 >>> s.check()
8276 sat
8277 """
8278 ctx = _get_ctx(ctx)
8279 return Solver(Z3_mk_simple_solver(ctx.ref()), ctx, logFile)
8280
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 9077 of file z3py.py.

9077def simplifier_description(name, ctx=None):
9078 """Return the description of the simplifier identified by name."""
9079 return Z3_simplifier_get_descr(_get_ctx(ctx).ref(), name)
9080
9081
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 9072 of file z3py.py.

9072def simplifier_name(i, ctx=None):
9073 """Return the name of the i-th simplifier supported by the given context."""
9074 return Z3_get_simplifier_name(_get_ctx(ctx).ref(), i)
9075
9076
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 9727 of file z3py.py.

9727def simplify(a, *arguments, **keywords):
9728 """Simplify the expression `a` using the given options.
9729
9730 This function has many options. Use `help_simplify` to obtain the complete list.
9731
9732 >>> x = Int('x')
9733 >>> y = Int('y')
9734 >>> simplify(x + 1 + y + x + 1)
9735 2 + 2*x + y
9736 >>> simplify((x + 1)*(y + 1), som=True)
9737 1 + x + y + x*y
9738 >>> simplify(Distinct(x, y, 1), blast_distinct=True)
9739 And(Not(x == y), Not(x == 1), Not(y == 1))
9740 >>> simplify(And(x == 0, y == 1), elim_and=True)
9741 Not(Or(Not(x == 0), Not(y == 1)))
9742 """
9743 if z3_debug():
9744 _z3_assert(is_expr(a), "Z3 expression expected")
9745 if len(arguments) > 0 or len(keywords) > 0:
9746 p = args2params(arguments, keywords, a.ctx)
9747 return _to_expr_ref(Z3_simplify_ex(a.ctx_ref(), a.as_ast(), p.params), a.ctx)
9748 else:
9749 return _to_expr_ref(Z3_simplify(a.ctx_ref(), a.as_ast()), a.ctx)
9750
9751
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 9757 of file z3py.py.

9757def simplify_param_descrs():
9758 """Return the set of parameter descriptions for Z3 `simplify` procedure."""
9759 return ParamDescrsRef(Z3_simplify_get_param_descrs(main_ctx().ref()), main_ctx())
9760
9761
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 5520 of file z3py.py.

5520def Singleton(elem):
5521 """Create a singleton finite set containing elem.
5522 >>> Singleton(IntVal(1))
5523 set.singleton(1)
5524 """
5525 ctx = elem.ctx
5526 return FiniteSetRef(Z3_mk_finite_set_singleton(ctx.ref(), elem.as_ast()), ctx)
5527
5528
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 9989 of file z3py.py.

9989def solve(*args, **keywords):
9990 """Solve the constraints `*args`.
9991
9992 This is a simple function for creating demonstrations. It creates a solver,
9993 configure it using the options in `keywords`, adds the constraints
9994 in `args`, and invokes check.
9995
9996 >>> a = Int('a')
9997 >>> solve(a > 0, a < 2)
9998 [a = 1]
9999 """
10000 show = keywords.pop("show", False)
10001 s = Solver()
10002 s.set(**keywords)
10003 s.add(*args)
10004 if show:
10005 print(s)
10006 r = s.check()
10007 if r == unsat:
10008 print("no solution")
10009 elif r == unknown:
10010 print("failed to solve")
10011 try:
10012 print(s.model())
10013 except Z3Exception:
10014 return
10015 else:
10016 print(s.model())
10017
10018

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

10019def solve_using(s, *args, **keywords):
10020 """Solve the constraints `*args` using solver `s`.
10021
10022 This is a simple function for creating demonstrations. It is similar to `solve`,
10023 but it uses the given solver `s`.
10024 It configures solver `s` using the options in `keywords`, adds the constraints
10025 in `args`, and invokes check.
10026 """
10027 show = keywords.pop("show", False)
10028 if z3_debug():
10029 _z3_assert(isinstance(s, Solver), "Solver object expected")
10030 s.set(**keywords)
10031 s.add(*args)
10032 if show:
10033 print("Problem:")
10034 print(s)
10035 r = s.check()
10036 if r == unsat:
10037 print("no solution")
10038 elif r == unknown:
10039 print("failed to solve")
10040 try:
10041 print(s.model())
10042 except Z3Exception:
10043 return
10044 else:
10045 if show:
10046 print("Solution:")
10047 print(s.model())
10048
10049

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

8248def SolverFor(logic, ctx=None, logFile=None):
8249 """Create a solver customized for the given logic.
8250
8251 The parameter `logic` is a string. It should be contains
8252 the name of a SMT-LIB logic.
8253 See http://www.smtlib.org/ for the name of all available logics.
8254
8255 >>> s = SolverFor("QF_LIA")
8256 >>> x = Int('x')
8257 >>> s.add(x > 0)
8258 >>> s.add(x < 2)
8259 >>> s.check()
8260 sat
8261 >>> s.model()
8262 [x = 1]
8263 """
8264 ctx = _get_ctx(ctx)
8265 logic = to_symbol(logic)
8266 return Solver(Z3_mk_solver_for_logic(ctx.ref(), logic), ctx, logFile)
8267
8268
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 3694 of file z3py.py.

3694def Sqrt(a, ctx=None):
3695 """ Return a Z3 expression which represents the square root of a.
3696
3697 >>> x = Real('x')
3698 >>> Sqrt(x)
3699 x**(1/2)
3700 """
3701 if not is_expr(a):
3702 ctx = _get_ctx(ctx)
3703 a = RealVal(a, ctx)
3704 return a ** "1/2"
3705
3706

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

4589def SRem(a, b):
4590 """Create the Z3 expression signed remainder.
4591
4592 Use the operator % for signed modulus, and URem() for unsigned remainder.
4593
4594 >>> x = BitVec('x', 32)
4595 >>> y = BitVec('y', 32)
4596 >>> SRem(x, y)
4597 SRem(x, y)
4598 >>> SRem(x, y).sort()
4599 BitVec(32)
4600 >>> (x % y).sexpr()
4601 '(bvsmod x y)'
4602 >>> SRem(x, y).sexpr()
4603 '(bvsrem x y)'
4604 """
4605 _check_bv_args(a, b)
4606 a, b = _coerce_exprs(a, b)
4607 return BitVecRef(Z3_mk_bvsrem(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4608
4609
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 12333 of file z3py.py.

12333def Star(re):
12334 """Create the regular expression accepting zero or more repetitions of argument.
12335 >>> re = Star(Re("a"))
12336 >>> print(simplify(InRe("aa", re)))
12337 True
12338 >>> print(simplify(InRe("ab", re)))
12339 False
12340 >>> print(simplify(InRe("", re)))
12341 True
12342 """
12343 if z3_debug():
12344 _z3_assert(is_expr(re), "expression expected")
12345 return ReRef(Z3_mk_re_star(re.ctx_ref(), re.as_ast()), re.ctx)
12346
12347
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 5142 of file z3py.py.

5142def Store(a, *args):
5143 """Return a Z3 store array expression.
5144
5145 >>> a = Array('a', IntSort(), IntSort())
5146 >>> i, v = Ints('i v')
5147 >>> s = Store(a, i, v)
5148 >>> s.sort()
5149 Array(Int, Int)
5150 >>> prove(s[i] == v)
5151 proved
5152 >>> j = Int('j')
5153 >>> prove(Implies(i != j, s[j] == a[j]))
5154 proved
5155 """
5156 return Update(a, args)
5157
5158

Referenced by ModelRef.get_interp().

◆ StrFromCode()

StrFromCode ( c)
Convert code to a string

Definition at line 12185 of file z3py.py.

12185def StrFromCode(c):
12186 """Convert code to a string"""
12187 if not is_expr(c):
12188 c = _py2expr(c)
12189 return SeqRef(Z3_mk_string_from_code(c.ctx_ref(), c.as_ast()), c.ctx)
12190
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 11932 of file z3py.py.

11932def String(name, ctx=None):
11933 """Return a string constant named `name`. If `ctx=None`, then the global context is used.
11934
11935 >>> x = String('x')
11936 """
11937 ctx = _get_ctx(ctx)
11938 return SeqRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), StringSort(ctx).ast), ctx)
11939
11940

◆ Strings()

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

Definition at line 11941 of file z3py.py.

11941def Strings(names, ctx=None):
11942 """Return a tuple of String constants. """
11943 ctx = _get_ctx(ctx)
11944 if isinstance(names, str):
11945 names = names.split(" ")
11946 return [String(name, ctx) for name in names]
11947
11948

◆ StringSort()

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

Definition at line 11744 of file z3py.py.

11744def StringSort(ctx=None):
11745 """Create a string sort
11746 >>> s = StringSort()
11747 >>> print(s)
11748 String
11749 """
11750 ctx = _get_ctx(ctx)
11751 return SeqSortRef(Z3_mk_string_sort(ctx.ref()), ctx)
11752

◆ StringVal()

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

Definition at line 11925 of file z3py.py.

11925def StringVal(s, ctx=None):
11926 """create a string expression"""
11927 s = "".join(str(ch) if 32 <= ord(ch) and ord(ch) < 127 else "\\u{%x}" % (ord(ch)) for ch in s)
11928 ctx = _get_ctx(ctx)
11929 return SeqRef(Z3_mk_string(ctx.ref(), s), ctx)
11930
11931
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 12179 of file z3py.py.

12179def StrToCode(s):
12180 """Convert a unit length string to integer code"""
12181 if not is_expr(s):
12182 s = _py2expr(s)
12183 return ArithRef(Z3_mk_string_to_code(s.ctx_ref(), s.as_ast()), s.ctx)
12184
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 12156 of file z3py.py.

12156def StrToInt(s):
12157 """Convert string expression to integer
12158 >>> a = StrToInt("1")
12159 >>> simplify(1 == a)
12160 True
12161 >>> b = StrToInt("2")
12162 >>> simplify(1 == b)
12163 False
12164 >>> c = StrToInt(IntToStr(2))
12165 >>> simplify(1 == c)
12166 False
12167 """
12168 s = _coerce_seq(s)
12169 return ArithRef(Z3_mk_str_to_int(s.ctx_ref(), s.as_ast()), s.ctx)
12170
12171
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 11963 of file z3py.py.

11963def SubSeq(s, offset, length):
11964 """Extract substring or subsequence starting at offset.
11965
11966 This is a convenience function that redirects to Extract(s, offset, length).
11967
11968 >>> s = StringVal("hello world")
11969 >>> SubSeq(s, 0, 5) # Extract "hello"
11970 str.substr("hello world", 0, 5)
11971 >>> simplify(SubSeq(StringVal("testing"), 2, 4))
11972 "stin"
11973 """
11974 return Extract(s, offset, length)
11975
11976

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

9762def substitute(t, *m):
9763 """Apply substitution m on t, m is a list of pairs of the form (from, to).
9764 Every occurrence in t of from is replaced with to.
9765
9766 >>> x = Int('x')
9767 >>> y = Int('y')
9768 >>> substitute(x + 1, (x, y + 1))
9769 y + 1 + 1
9770 >>> f = Function('f', IntSort(), IntSort())
9771 >>> substitute(f(x) + f(y), (f(x), IntVal(1)), (f(y), IntVal(1)))
9772 1 + 1
9773 """
9774 if isinstance(m, tuple):
9775 m1 = _get_args(m)
9776 if isinstance(m1, list) and all(isinstance(p, tuple) for p in m1):
9777 m = m1
9778 if z3_debug():
9779 _z3_assert(is_expr(t), "Z3 expression expected")
9780 _z3_assert(
9781 all([isinstance(p, tuple) and is_expr(p[0]) and is_expr(p[1]) for p in m]),
9782 "Z3 invalid substitution, expression pairs expected.")
9783 _z3_assert(
9784 all([p[0].sort().eq(p[1].sort()) for p in m]),
9785 'Z3 invalid substitution, mismatching "from" and "to" sorts.')
9786 num = len(m)
9787 _from = (Ast * num)()
9788 _to = (Ast * num)()
9789 for i in range(num):
9790 _from[i] = m[i][0].as_ast()
9791 _to[i] = m[i][1].as_ast()
9792 return _to_expr_ref(Z3_substitute(t.ctx.ref(), t.as_ast(), num, _from, _to), t.ctx)
9793
9794
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 9815 of file z3py.py.

9815def substitute_funs(t, *m):
9816 """Apply substitution m on t, m is a list of pairs of a function and expression (from, to)
9817 Every occurrence in to of the function from is replaced with the expression to.
9818 The expression to can have free variables, that refer to the arguments of from.
9819 For examples, see
9820 """
9821 if isinstance(m, tuple):
9822 m1 = _get_args(m)
9823 if isinstance(m1, list) and all(isinstance(p, tuple) for p in m1):
9824 m = m1
9825 if z3_debug():
9826 _z3_assert(is_expr(t), "Z3 expression expected")
9827 _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.")
9828 num = len(m)
9829 _from = (FuncDecl * num)()
9830 _to = (Ast * num)()
9831 for i in range(num):
9832 _from[i] = m[i][0].as_func_decl()
9833 _to[i] = m[i][1].as_ast()
9834 return _to_expr_ref(Z3_substitute_funs(t.ctx.ref(), t.as_ast(), num, _from, _to), t.ctx)
9835
9836
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 9795 of file z3py.py.

9795def substitute_vars(t, *m):
9796 """Substitute the free variables in t with the expression in m.
9797
9798 >>> v0 = Var(0, IntSort())
9799 >>> v1 = Var(1, IntSort())
9800 >>> x = Int('x')
9801 >>> f = Function('f', IntSort(), IntSort(), IntSort())
9802 >>> # replace v0 with x+1 and v1 with x
9803 >>> substitute_vars(f(v0, v1), x + 1, x)
9804 f(x + 1, x)
9805 """
9806 if z3_debug():
9807 _z3_assert(is_expr(t), "Z3 expression expected")
9808 _z3_assert(all([is_expr(n) for n in m]), "Z3 invalid substitution, list of expressions expected.")
9809 num = len(m)
9810 _to = (Ast * num)()
9811 for i in range(num):
9812 _to[i] = m[i].as_ast()
9813 return _to_expr_ref(Z3_substitute_vars(t.ctx.ref(), t.as_ast(), num, _to), t.ctx)
9814
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 11949 of file z3py.py.

11949def SubString(s, offset, length):
11950 """Extract substring or subsequence starting at offset.
11951
11952 This is a convenience function that redirects to Extract(s, offset, length).
11953
11954 >>> s = StringVal("hello world")
11955 >>> SubString(s, 6, 5) # Extract "world"
11956 str.substr("hello world", 6, 5)
11957 >>> simplify(SubString(StringVal("hello"), 1, 3))
11958 "ell"
11959 """
11960 return Extract(s, offset, length)
11961
11962

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

12032def SuffixOf(a, b):
12033 """Check if 'a' is a suffix of 'b'
12034 >>> s1 = SuffixOf("ab", "abc")
12035 >>> simplify(s1)
12036 False
12037 >>> s2 = SuffixOf("bc", "abc")
12038 >>> simplify(s2)
12039 True
12040 """
12041 ctx = _get_ctx2(a, b)
12042 a = _coerce_seq(a, ctx)
12043 b = _coerce_seq(b, ctx)
12044 return BoolRef(Z3_mk_seq_suffix(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
12045
12046
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 9837 of file z3py.py.

9837def Sum(*args):
9838 """Create the sum of the Z3 expressions.
9839
9840 >>> a, b, c = Ints('a b c')
9841 >>> Sum(a, b, c)
9842 a + b + c
9843 >>> Sum([a, b, c])
9844 a + b + c
9845 >>> A = IntVector('a', 5)
9846 >>> Sum(A)
9847 a__0 + a__1 + a__2 + a__3 + a__4
9848 """
9849 args = _get_args(args)
9850 if len(args) == 0:
9851 return 0
9852 ctx = _ctx_from_ast_arg_list(args)
9853 if ctx is None:
9854 return _reduce(lambda a, b: a + b, args, 0)
9855 args = _coerce_expr_list(args, ctx)
9856 if is_bv(args[0]) or isinstance(args[0], FiniteFieldRef):
9857 return _reduce(lambda a, b: a + b, args, 0)
9858 else:
9859 _args, sz = _to_ast_array(args)
9860 return _to_expr_ref(Z3_mk_add(ctx.ref(), sz, _args), ctx)
9861
9862
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 9416 of file z3py.py.

9416def tactic_description(name, ctx=None):
9417 """Return a short description for the tactic named `name`.
9418
9419 >>> d = tactic_description('simplify')
9420 """
9421 ctx = _get_ctx(ctx)
9422 return Z3_tactic_get_descr(ctx.ref(), name)
9423
9424
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 9405 of file z3py.py.

9405def tactics(ctx=None):
9406 """Return a list of all available tactics in Z3.
9407
9408 >>> l = tactics()
9409 >>> l.count('simplify') == 1
9410 True
9411 """
9412 ctx = _get_ctx(ctx)
9413 return [Z3_get_tactic_name(ctx.ref(), i) for i in range(Z3_get_num_tactics(ctx.ref()))]
9414
9415
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 9273 of file z3py.py.

9273def Then(*ts, **ks):
9274 """Return a tactic that applies the tactics in `*ts` in sequence. Shorthand for AndThen(*ts, **ks).
9275
9276 >>> x, y = Ints('x y')
9277 >>> t = Then(Tactic('simplify'), Tactic('solve-eqs'))
9278 >>> t(And(x == 0, y > x + 1))
9279 [[Not(y <= 1)]]
9280 >>> t(And(x == 0, y > x + 1)).as_expr()
9281 Not(y <= 1)
9282 """
9283 return AndThen(*ts, **ks)
9284
9285

◆ to_Ast()

to_Ast ( ptr)

Definition at line 12417 of file z3py.py.

12417def to_Ast(ptr,):
12418 ast = Ast(ptr)
12419 super(ctypes.c_void_p, ast).__init__(ptr)
12420 return ast
12421

◆ to_AstVectorObj()

to_AstVectorObj ( ptr)

Definition at line 12427 of file z3py.py.

12427def to_AstVectorObj(ptr,):
12428 v = AstVectorObj(ptr)
12429 super(ctypes.c_void_p, v).__init__(ptr)
12430 return v
12431
12432# NB. my-hacky-class only works for a single instance of OnClause
12433# it should be replaced with a proper correlation between OnClause
12434# and object references that can be passed over the FFI.
12435# for UserPropagator we use a global dictionary, which isn't great code.
12436

◆ to_ContextObj()

to_ContextObj ( ptr)

Definition at line 12422 of file z3py.py.

12422def to_ContextObj(ptr,):
12423 ctx = ContextObj(ptr)
12424 super(ctypes.c_void_p, ctx).__init__(ptr)
12425 return ctx
12426

◆ 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(), Complex(), 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 3659 of file z3py.py.

3659def ToInt(a):
3660 """ Return the Z3 expression ToInt(a).
3661
3662 >>> x = Real('x')
3663 >>> x.sort()
3664 Real
3665 >>> n = ToInt(x)
3666 >>> n
3667 ToInt(x)
3668 >>> n.sort()
3669 Int
3670 """
3671 if z3_debug():
3672 _z3_assert(a.is_real(), "Z3 real expression expected.")
3673 ctx = a.ctx
3674 return ArithRef(Z3_mk_real2int(ctx.ref(), a.as_ast()), ctx)
3675
3676
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 3639 of file z3py.py.

3639def ToReal(a):
3640 """ Return the Z3 expression ToReal(a).
3641
3642 >>> x = Int('x')
3643 >>> x.sort()
3644 Int
3645 >>> n = ToReal(x)
3646 >>> n
3647 ToReal(x)
3648 >>> n.sort()
3649 Real
3650 """
3651 ctx = a.ctx
3652 if isinstance(a, BoolRef):
3653 return If(a, RealVal(1, ctx), RealVal(0, ctx))
3654 if z3_debug():
3655 _z3_assert(a.is_int(), "Z3 integer expression expected.")
3656 return ArithRef(Z3_mk_int2real(ctx.ref(), a.as_ast()), ctx)
3657
3658
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 12410 of file z3py.py.

12410def TransitiveClosure(f):
12411 """Given a binary relation R, such that the two arguments have the same sort
12412 create the transitive closure relation R+.
12413 The transitive closure R+ is a new relation.
12414 """
12415 return FuncDeclRef(Z3_mk_transitive_closure(f.ctx_ref(), f.ast), f.ctx)
12416
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 12402 of file z3py.py.

12402def TreeOrder(a, index):
12403 return FuncDeclRef(Z3_mk_tree_order(a.ctx_ref(), a.ast, index), a.ctx)
12404
12405
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 9396 of file z3py.py.

9396def TryFor(t, ms, ctx=None):
9397 """Return a tactic that applies `t` to a given goal for `ms` milliseconds.
9398
9399 If `t` does not terminate in `ms` milliseconds, then it fails.
9400 """
9401 t = _to_tactic(t, ctx)
9402 return Tactic(Z3_tactic_try_for(t.ctx.ref(), t.tactic, ms), t.ctx)
9403
9404
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 6092 of file z3py.py.

6092def TupleSort(name, sorts, ctx=None):
6093 """Create a named tuple sort base on a set of underlying sorts
6094 Example:
6095 >>> pair, mk_pair, (first, second) = TupleSort("pair", [IntSort(), StringSort()])
6096 """
6097 tuple = Datatype(name, ctx)
6098 projects = [("project%d" % i, sorts[i]) for i in range(len(sorts))]
6099 tuple.declare(name, *projects)
6100 tuple = tuple.create()
6101 return tuple, tuple.constructor(0), [tuple.accessor(0, i) for i in range(len(sorts))]
6102
6103

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

4547def UDiv(a, b):
4548 """Create the Z3 expression (unsigned) division `self / other`.
4549
4550 Use the operator / for signed division.
4551
4552 >>> x = BitVec('x', 32)
4553 >>> y = BitVec('y', 32)
4554 >>> UDiv(x, y)
4555 UDiv(x, y)
4556 >>> UDiv(x, y).sort()
4557 BitVec(32)
4558 >>> (x / y).sexpr()
4559 '(bvsdiv x y)'
4560 >>> UDiv(x, y).sexpr()
4561 '(bvudiv x y)'
4562 """
4563 _check_bv_args(a, b)
4564 a, b = _coerce_exprs(a, b)
4565 return BitVecRef(Z3_mk_bvudiv(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4566
4567
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 4511 of file z3py.py.

4511def UGE(a, b):
4512 """Create the Z3 expression (unsigned) `other >= self`.
4513
4514 Use the operator >= for signed greater than or equal to.
4515
4516 >>> x, y = BitVecs('x y', 32)
4517 >>> UGE(x, y)
4518 UGE(x, y)
4519 >>> (x >= y).sexpr()
4520 '(bvsge x y)'
4521 >>> UGE(x, y).sexpr()
4522 '(bvuge x y)'
4523 """
4524 _check_bv_args(a, b)
4525 a, b = _coerce_exprs(a, b)
4526 return BoolRef(Z3_mk_bvuge(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4527
4528
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 4529 of file z3py.py.

4529def UGT(a, b):
4530 """Create the Z3 expression (unsigned) `other > self`.
4531
4532 Use the operator > for signed greater than.
4533
4534 >>> x, y = BitVecs('x y', 32)
4535 >>> UGT(x, y)
4536 UGT(x, y)
4537 >>> (x > y).sexpr()
4538 '(bvsgt x y)'
4539 >>> UGT(x, y).sexpr()
4540 '(bvugt x y)'
4541 """
4542 _check_bv_args(a, b)
4543 a, b = _coerce_exprs(a, b)
4544 return BoolRef(Z3_mk_bvugt(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4545
4546
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 4475 of file z3py.py.

4475def ULE(a, b):
4476 """Create the Z3 expression (unsigned) `other <= self`.
4477
4478 Use the operator <= for signed less than or equal to.
4479
4480 >>> x, y = BitVecs('x y', 32)
4481 >>> ULE(x, y)
4482 ULE(x, y)
4483 >>> (x <= y).sexpr()
4484 '(bvsle x y)'
4485 >>> ULE(x, y).sexpr()
4486 '(bvule x y)'
4487 """
4488 _check_bv_args(a, b)
4489 a, b = _coerce_exprs(a, b)
4490 return BoolRef(Z3_mk_bvule(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4491
4492
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 4493 of file z3py.py.

4493def ULT(a, b):
4494 """Create the Z3 expression (unsigned) `other < self`.
4495
4496 Use the operator < for signed less than.
4497
4498 >>> x, y = BitVecs('x y', 32)
4499 >>> ULT(x, y)
4500 ULT(x, y)
4501 >>> (x < y).sexpr()
4502 '(bvslt x y)'
4503 >>> ULT(x, y).sexpr()
4504 '(bvult x y)'
4505 """
4506 _check_bv_args(a, b)
4507 a, b = _coerce_exprs(a, b)
4508 return BoolRef(Z3_mk_bvult(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4509
4510
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 12244 of file z3py.py.

12244def Union(*args):
12245 """Create union of regular expressions.
12246 >>> re = Union(Re("a"), Re("b"), Re("c"))
12247 >>> print (simplify(InRe("d", re)))
12248 False
12249 """
12250 args = _get_args(args)
12251 sz = len(args)
12252 if z3_debug():
12253 _z3_assert(sz > 0, "At least one argument expected.")
12254 arg0 = args[0]
12255 if is_finite_set(arg0):
12256 for a in args[1:]:
12257 if not is_finite_set(a):
12258 raise Z3Exception("All arguments must be regular expressions or finite sets.")
12259 arg0 = arg0 | a
12260 return arg0
12261 if z3_debug():
12262 _z3_assert(all([is_re(a) for a in args]), "All arguments must be regular expressions.")
12263 if sz == 1:
12264 return args[0]
12265 ctx = args[0].ctx
12266 v = (Ast * sz)()
12267 for i in range(sz):
12268 v[i] = args[i].as_ast()
12269 return ReRef(Z3_mk_re_union(ctx.ref(), sz, v), ctx)
12270
12271
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 12012 of file z3py.py.

12012def Unit(a):
12013 """Create a singleton sequence"""
12014 return SeqRef(Z3_mk_seq_unit(a.ctx_ref(), a.as_ast()), a.ctx)
12015
12016
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 5099 of file z3py.py.

5099def Update(a, *args):
5100 """Return a Z3 store array expression.
5101
5102 >>> a = Array('a', IntSort(), IntSort())
5103 >>> i, v = Ints('i v')
5104 >>> s = Update(a, i, v)
5105 >>> s.sort()
5106 Array(Int, Int)
5107 >>> prove(s[i] == v)
5108 proved
5109 >>> j = Int('j')
5110 >>> prove(Implies(i != j, s[j] == a[j]))
5111 proved
5112 """
5113 if z3_debug():
5114 _z3_assert(is_array_sort(a), "First argument must be a Z3 array expression")
5115 args = _get_args(args)
5116 ctx = a.ctx
5117 if len(args) <= 1:
5118 raise Z3Exception("array update requires index and value arguments")
5119 if len(args) == 2:
5120 i = args[0]
5121 v = args[1]
5122 i = a.sort().domain().cast(i)
5123 v = a.sort().range().cast(v)
5124 return _to_expr_ref(Z3_mk_store(ctx.ref(), a.as_ast(), i.as_ast(), v.as_ast()), ctx)
5125 v = a.sort().range().cast(args[-1])
5126 idxs = [a.sort().domain_n(i).cast(args[i]) for i in range(len(args)-1)]
5127 _args, sz = _to_ast_array(idxs)
5128 return _to_expr_ref(Z3_mk_store_n(ctx.ref(), a.as_ast(), sz, _args, v.as_ast()), ctx)
5129
5130
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 4568 of file z3py.py.

4568def URem(a, b):
4569 """Create the Z3 expression (unsigned) remainder `self % other`.
4570
4571 Use the operator % for signed modulus, and SRem() for signed remainder.
4572
4573 >>> x = BitVec('x', 32)
4574 >>> y = BitVec('y', 32)
4575 >>> URem(x, y)
4576 URem(x, y)
4577 >>> URem(x, y).sort()
4578 BitVec(32)
4579 >>> (x % y).sexpr()
4580 '(bvsmod x y)'
4581 >>> URem(x, y).sexpr()
4582 '(bvurem x y)'
4583 """
4584 _check_bv_args(a, b)
4585 a, b = _coerce_exprs(a, b)
4586 return BitVecRef(Z3_mk_bvurem(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4587
4588
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 12580 of file z3py.py.

12580def user_prop_binding(ctx, cb, q_ref, inst_ref):
12581 prop = _prop_closures.get(ctx)
12582 old_cb = prop.cb
12583 prop.cb = cb
12584 q = _to_expr_ref(to_Ast(q_ref), prop.ctx())
12585 inst = _to_expr_ref(to_Ast(inst_ref), prop.ctx())
12586 r = prop.binding(q, inst)
12587 prop.cb = old_cb
12588 return r
12589
12590

◆ user_prop_created()

user_prop_created ( ctx,
cb,
id )

Definition at line 12538 of file z3py.py.

12538def user_prop_created(ctx, cb, id):
12539 prop = _prop_closures.get(ctx)
12540 old_cb = prop.cb
12541 prop.cb = cb
12542 id = _to_expr_ref(to_Ast(id), prop.ctx())
12543 prop.created(id)
12544 prop.cb = old_cb
12545
12546

◆ user_prop_decide()

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

Definition at line 12572 of file z3py.py.

12572def user_prop_decide(ctx, cb, t_ref, idx, phase):
12573 prop = _prop_closures.get(ctx)
12574 old_cb = prop.cb
12575 prop.cb = cb
12576 t = _to_expr_ref(to_Ast(t_ref), prop.ctx())
12577 prop.decide(t, idx, phase)
12578 prop.cb = old_cb
12579

◆ user_prop_diseq()

user_prop_diseq ( ctx,
cb,
x,
y )

Definition at line 12563 of file z3py.py.

12563def user_prop_diseq(ctx, cb, x, y):
12564 prop = _prop_closures.get(ctx)
12565 old_cb = prop.cb
12566 prop.cb = cb
12567 x = _to_expr_ref(to_Ast(x), prop.ctx())
12568 y = _to_expr_ref(to_Ast(y), prop.ctx())
12569 prop.diseq(x, y)
12570 prop.cb = old_cb
12571

◆ user_prop_eq()

user_prop_eq ( ctx,
cb,
x,
y )

Definition at line 12554 of file z3py.py.

12554def user_prop_eq(ctx, cb, x, y):
12555 prop = _prop_closures.get(ctx)
12556 old_cb = prop.cb
12557 prop.cb = cb
12558 x = _to_expr_ref(to_Ast(x), prop.ctx())
12559 y = _to_expr_ref(to_Ast(y), prop.ctx())
12560 prop.eq(x, y)
12561 prop.cb = old_cb
12562

◆ user_prop_final()

user_prop_final ( ctx,
cb )

Definition at line 12547 of file z3py.py.

12547def user_prop_final(ctx, cb):
12548 prop = _prop_closures.get(ctx)
12549 old_cb = prop.cb
12550 prop.cb = cb
12551 prop.final()
12552 prop.cb = old_cb
12553

◆ user_prop_fixed()

user_prop_fixed ( ctx,
cb,
id,
value )

Definition at line 12529 of file z3py.py.

12529def user_prop_fixed(ctx, cb, id, value):
12530 prop = _prop_closures.get(ctx)
12531 old_cb = prop.cb
12532 prop.cb = cb
12533 id = _to_expr_ref(to_Ast(id), prop.ctx())
12534 value = _to_expr_ref(to_Ast(value), prop.ctx())
12535 prop.fixed(id, value)
12536 prop.cb = old_cb
12537

◆ user_prop_fresh()

user_prop_fresh ( ctx,
_new_ctx )

Definition at line 12515 of file z3py.py.

12515def user_prop_fresh(ctx, _new_ctx):
12516 _prop_closures.set_threaded()
12517 prop = _prop_closures.get(ctx)
12518 nctx = Context()
12519 Z3_del_context(nctx.ctx)
12520 new_ctx = to_ContextObj(_new_ctx)
12521 nctx.ctx = new_ctx
12522 nctx.eh = Z3_set_error_handler(new_ctx, z3_error_handler)
12523 nctx.owner = False
12524 new_prop = prop.fresh(nctx)
12525 _prop_closures.set(new_prop.id, new_prop)
12526 return new_prop.id
12527
12528
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 12509 of file z3py.py.

12509def user_prop_pop(ctx, cb, num_scopes):
12510 prop = _prop_closures.get(ctx)
12511 prop.cb = cb
12512 prop.pop(num_scopes)
12513
12514

◆ user_prop_push()

user_prop_push ( ctx,
cb )

Definition at line 12503 of file z3py.py.

12503def user_prop_push(ctx, cb):
12504 prop = _prop_closures.get(ctx)
12505 prop.cb = cb
12506 prop.push()
12507
12508

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

1602def Var(idx : int, s : SortRef) -> ExprRef:
1603 """Create a Z3 free variable. Free variables are used to create quantified formulas.
1604 A free variable with index n is bound when it occurs within the scope of n+1 quantified
1605 declarations.
1606
1607 >>> Var(0, IntSort())
1608 Var(0)
1609 >>> eq(Var(0, IntSort()), Var(0, BoolSort()))
1610 False
1611 """
1612 if z3_debug():
1613 _z3_assert(is_sort(s), "Z3 sort expected")
1614 return _to_expr_ref(Z3_mk_bound(s.ctx_ref(), idx, s.ast), s.ctx)
1615
1616
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 9690 of file z3py.py.

9690def When(p, t, ctx=None):
9691 """Return a tactic that applies tactic `t` only if probe `p` evaluates to true.
9692 Otherwise, it returns the input goal unmodified.
9693
9694 >>> t = When(Probe('size') > 2, Tactic('simplify'))
9695 >>> x, y = Ints('x y')
9696 >>> g = Goal()
9697 >>> g.add(x > 0)
9698 >>> g.add(y > 0)
9699 >>> t(g)
9700 [[x > 0, y > 0]]
9701 >>> g.add(x == y + 1)
9702 >>> t(g)
9703 [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
9704 """
9705 p = _to_probe(p, ctx)
9706 t = _to_tactic(t, ctx)
9707 return Tactic(Z3_tactic_when(t.ctx.ref(), p.probe, t.tactic), t.ctx)
9708
9709
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 9347 of file z3py.py.

9347def With(t, *args, **keys):
9348 """Return a tactic that applies tactic `t` using the given configuration options.
9349
9350 >>> x, y = Ints('x y')
9351 >>> t = With(Tactic('simplify'), som=True)
9352 >>> t((x + 1)*(y + 2) == 0)
9353 [[2*x + y + x*y == -2]]
9354 """
9355 ctx = keys.pop("ctx", None)
9356 t = _to_tactic(t, ctx)
9357 p = args2params(args, keys, t.ctx)
9358 return Tactic(Z3_tactic_using_params(t.ctx.ref(), t.tactic, p.params), t.ctx)
9359
9360
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 9361 of file z3py.py.

9361def WithParams(t, p):
9362 """Return a tactic that applies tactic `t` using the given configuration options.
9363
9364 >>> x, y = Ints('x y')
9365 >>> p = ParamsRef()
9366 >>> p.set("som", True)
9367 >>> t = WithParams(Tactic('simplify'), p)
9368 >>> t((x + 1)*(y + 2) == 0)
9369 [[2*x + y + x*y == -2]]
9370 """
9371 t = _to_tactic(t, None)
9372 return Tactic(Z3_tactic_using_params(t.ctx.ref(), t.tactic, p.params), t.ctx)
9373
9374

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

1959def Xor(a, b, ctx=None):
1960 """Create a Z3 Xor expression.
1961
1962 >>> p, q = Bools('p q')
1963 >>> Xor(p, q)
1964 Xor(p, q)
1965 >>> simplify(Xor(p, q))
1966 Not(p == q)
1967 """
1968 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1969 s = BoolSort(ctx)
1970 a = s.cast(a)
1971 b = s.cast(b)
1972 return BoolRef(Z3_mk_xor(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
1973
1974
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 4704 of file z3py.py.

4704def ZeroExt(n, a):
4705 """Return a bit-vector expression with `n` extra zero-bits.
4706
4707 >>> x = BitVec('x', 16)
4708 >>> n = ZeroExt(8, x)
4709 >>> n.size()
4710 24
4711 >>> n
4712 ZeroExt(8, x)
4713 >>> n.sort()
4714 BitVec(24)
4715 >>> v0 = BitVecVal(2, 2)
4716 >>> v0
4717 2
4718 >>> v0.size()
4719 2
4720 >>> v = simplify(ZeroExt(6, v0))
4721 >>> v
4722 2
4723 >>> v.size()
4724 8
4725 """
4726 if z3_debug():
4727 _z3_assert(_is_int(n), "First argument must be an integer")
4728 _z3_assert(is_bv(a), "Second argument must be a Z3 bit-vector expression")
4729 return BitVecRef(Z3_mk_zero_ext(a.ctx_ref(), n, a.as_ast()), a.ctx)
4730
4731
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 10242 of file z3py.py.

◆ _dflt_fpsort_sbits

int _dflt_fpsort_sbits = 53
protected

Definition at line 10243 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 10241 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 12437 of file z3py.py.

◆ _on_clause_eh

_on_clause_eh = Z3_on_clause_eh(on_clause_eh)
protected

Definition at line 12445 of file z3py.py.

◆ _on_model_eh

_on_model_eh = on_model_eh_type(_global_on_model)
protected

Definition at line 8713 of file z3py.py.

◆ _on_models

dict _on_models = {}
protected

Definition at line 8705 of file z3py.py.

◆ _prop_closures

_prop_closures = None
protected

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

◆ _user_prop_binding

_user_prop_binding = Z3_on_binding_eh(user_prop_binding)
protected

Definition at line 12600 of file z3py.py.

◆ _user_prop_created

_user_prop_created = Z3_created_eh(user_prop_created)
protected

Definition at line 12595 of file z3py.py.

◆ _user_prop_decide

_user_prop_decide = Z3_decide_eh(user_prop_decide)
protected

Definition at line 12599 of file z3py.py.

◆ _user_prop_diseq

_user_prop_diseq = Z3_eq_eh(user_prop_diseq)
protected

Definition at line 12598 of file z3py.py.

◆ _user_prop_eq

_user_prop_eq = Z3_eq_eh(user_prop_eq)
protected

Definition at line 12597 of file z3py.py.

◆ _user_prop_final

_user_prop_final = Z3_final_eh(user_prop_final)
protected

Definition at line 12596 of file z3py.py.

◆ _user_prop_fixed

_user_prop_fixed = Z3_fixed_eh(user_prop_fixed)
protected

Definition at line 12594 of file z3py.py.

◆ _user_prop_fresh

_user_prop_fresh = Z3_fresh_eh(user_prop_fresh)
protected

Definition at line 12593 of file z3py.py.

◆ _user_prop_pop

_user_prop_pop = Z3_pop_eh(user_prop_pop)
protected

Definition at line 12592 of file z3py.py.

◆ _user_prop_push

_user_prop_push = Z3_push_eh(user_prop_push)
protected

Definition at line 12591 of file z3py.py.

◆ sat

Definition at line 7676 of file z3py.py.

◆ unknown

Definition at line 7678 of file z3py.py.

◆ unsat

Definition at line 7677 of file z3py.py.

◆ Z3_DEBUG

Z3_DEBUG = __debug__

Definition at line 67 of file z3py.py.