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

Data Structures

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

Functions

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

Variables

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

Function Documentation

◆ _and_then()

_and_then ( t1,
t2,
ctx = None )
protected

Definition at line 8635 of file z3py.py.

8635def _and_then(t1, t2, ctx=None):
8636 t1 = _to_tactic(t1, ctx)
8637 t2 = _to_tactic(t2, ctx)
8638 if z3_debug():
8639 _z3_assert(t1.ctx == t2.ctx, "Context mismatch")
8640 return Tactic(Z3_tactic_and_then(t1.ctx.ref(), t1.tactic, t2.tactic), t1.ctx)
8641
8642
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 4773 of file z3py.py.

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

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

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

◆ _check_fp_args()

_check_fp_args ( a,
b )
protected

Definition at line 10747 of file z3py.py.

10747def _check_fp_args(a, b):
10748 if z3_debug():
10749 _z3_assert(is_fp(a) or is_fp(b), "First or second argument must be a Z3 floating-point expression")
10750
10751

◆ _check_same_sort()

_check_same_sort ( a,
b,
ctx = None )
protected

Definition at line 1289 of file z3py.py.

1289def _check_same_sort(a, b, ctx=None):
1290 if not isinstance(a, ExprRef):
1291 return False
1292 if not isinstance(b, ExprRef):
1293 return False
1294 if ctx is None:
1295 ctx = a.ctx
1296
1297 a_sort = Z3_get_sort(ctx.ctx, a.ast)
1298 b_sort = Z3_get_sort(ctx.ctx, b.ast)
1299 return Z3_is_eq_sort(ctx.ctx, a_sort, b_sort)
1300
1301
bool Z3_API Z3_is_eq_sort(Z3_context c, Z3_sort s1, Z3_sort s2)
compare sorts.
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.

Referenced by _coerce_exprs().

◆ _coerce_char()

_coerce_char ( ch,
ctx = None )
protected

Definition at line 11190 of file z3py.py.

11190def _coerce_char(ch, ctx=None):
11191 if isinstance(ch, str):
11192 ctx = _get_ctx(ctx)
11193 ch = CharVal(ch, ctx)
11194 if not is_expr(ch):
11195 raise Z3Exception("Character expression expected")
11196 return ch
11197

◆ _coerce_expr_list()

_coerce_expr_list ( alist,
ctx = None )
protected

Definition at line 1333 of file z3py.py.

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

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

◆ _coerce_expr_merge()

_coerce_expr_merge ( s,
a )
protected

Definition at line 1271 of file z3py.py.

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

Referenced by _coerce_exprs().

◆ _coerce_exprs()

_coerce_exprs ( a,
b,
ctx = None )
protected

Definition at line 1302 of file z3py.py.

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

Referenced by ArithRef.__add__(), BitVecRef.__add__(), BitVecRef.__and__(), ArithRef.__div__(), BitVecRef.__div__(), ExprRef.__eq__(), ArithRef.__ge__(), BitVecRef.__ge__(), ArithRef.__gt__(), BitVecRef.__gt__(), ArithRef.__le__(), BitVecRef.__le__(), BitVecRef.__lshift__(), ArithRef.__lt__(), BitVecRef.__lt__(), ArithRef.__mod__(), BitVecRef.__mod__(), ArithRef.__mul__(), BitVecRef.__mul__(), ExprRef.__ne__(), BitVecRef.__or__(), ArithRef.__pow__(), ArithRef.__radd__(), BitVecRef.__radd__(), BitVecRef.__rand__(), ArithRef.__rdiv__(), BitVecRef.__rdiv__(), BitVecRef.__rlshift__(), ArithRef.__rmod__(), BitVecRef.__rmod__(), ArithRef.__rmul__(), BitVecRef.__rmul__(), BitVecRef.__ror__(), ArithRef.__rpow__(), BitVecRef.__rrshift__(), BitVecRef.__rshift__(), ArithRef.__rsub__(), BitVecRef.__rsub__(), BitVecRef.__rxor__(), ArithRef.__sub__(), BitVecRef.__sub__(), BitVecRef.__xor__(), BVAddNoOverflow(), BVAddNoUnderflow(), BVMulNoOverflow(), BVMulNoUnderflow(), BVSDivNoOverflow(), BVSubNoOverflow(), BVSubNoUnderflow(), Extract(), If(), LShR(), RotateLeft(), RotateRight(), SRem(), UDiv(), UGE(), UGT(), ULE(), ULT(), and URem().

◆ _coerce_fp_expr_list()

_coerce_fp_expr_list ( alist,
ctx )
protected

Definition at line 9696 of file z3py.py.

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

◆ _coerce_seq()

_coerce_seq ( s,
ctx = None )
protected

Definition at line 11240 of file z3py.py.

11240def _coerce_seq(s, ctx=None):
11241 if isinstance(s, str):
11242 ctx = _get_ctx(ctx)
11243 s = StringVal(s, ctx)
11244 if not is_expr(s):
11245 raise Z3Exception("Non-expression passed as a sequence")
11246 if not is_seq(s):
11247 raise Z3Exception("Non-sequence passed as a sequence")
11248 return s
11249
11250

Referenced by Concat().

◆ _ctx_from_ast_arg_list()

_ctx_from_ast_arg_list ( args,
default_ctx = None )
protected

Definition at line 528 of file z3py.py.

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

Referenced by _ctx_from_ast_args(), And(), Distinct(), If(), Implies(), IsMember(), IsSubset(), Not(), Or(), SetAdd(), SetDel(), SetDifference(), SetIntersect(), SetUnion(), and Xor().

◆ _ctx_from_ast_args()

_ctx_from_ast_args ( * args)
protected

Definition at line 542 of file z3py.py.

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

◆ _dflt_fps()

_dflt_fps ( ctx = None)
protected

Definition at line 9692 of file z3py.py.

9692def _dflt_fps(ctx=None):
9693 return get_default_fp_sort(ctx)
9694
9695

◆ _dflt_rm()

_dflt_rm ( ctx = None)
protected

Definition at line 9688 of file z3py.py.

9688def _dflt_rm(ctx=None):
9689 return get_default_rounding_mode(ctx)
9690
9691

◆ _dict2darray()

_dict2darray ( decls,
ctx )
protected

Definition at line 9561 of file z3py.py.

9561def _dict2darray(decls, ctx):
9562 sz = len(decls)
9563 _names = (Symbol * sz)()
9564 _decls = (FuncDecl * sz)()
9565 i = 0
9566 for k in decls:
9567 v = decls[k]
9568 if z3_debug():
9569 _z3_assert(isinstance(k, str), "String expected")
9570 _z3_assert(is_func_decl(v) or is_const(v), "Z3 declaration or constant expected")
9571 _names[i] = to_symbol(k, ctx)
9572 if is_const(v):
9573 _decls[i] = v.decl().ast
9574 else:
9575 _decls[i] = v.ast
9576 i = i + 1
9577 return sz, _names, _decls
9578

◆ _dict2sarray()

_dict2sarray ( sorts,
ctx )
protected

Definition at line 9545 of file z3py.py.

9545def _dict2sarray(sorts, ctx):
9546 sz = len(sorts)
9547 _names = (Symbol * sz)()
9548 _sorts = (Sort * sz)()
9549 i = 0
9550 for k in sorts:
9551 v = sorts[k]
9552 if z3_debug():
9553 _z3_assert(isinstance(k, str), "String expected")
9554 _z3_assert(is_sort(v), "Z3 sort expected")
9555 _names[i] = to_symbol(k, ctx)
9556 _sorts[i] = v.ast
9557 i = i + 1
9558 return sz, _names, _sorts
9559
9560

◆ _get_args()

_get_args ( args)
protected

Definition at line 152 of file z3py.py.

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

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

◆ _get_args_ast_list()

_get_args_ast_list ( args)
protected

Definition at line 168 of file z3py.py.

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

◆ _get_ctx()

Context _get_ctx ( ctx)
protected

Definition at line 287 of file z3py.py.

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

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

◆ _get_ctx2()

_get_ctx2 ( a,
b,
ctx = None )
protected

Definition at line 11251 of file z3py.py.

11251def _get_ctx2(a, b, ctx=None):
11252 if is_expr(a):
11253 return a.ctx
11254 if is_expr(b):
11255 return b.ctx
11256 if ctx is None:
11257 ctx = main_ctx()
11258 return ctx
11259
11260

◆ _global_on_model()

_global_on_model ( ctx)
protected

Definition at line 8139 of file z3py.py.

8139def _global_on_model(ctx):
8140 (fn, mdl) = _on_models[ctx]
8141 fn(mdl)
8142
8143

◆ _has_probe()

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

Definition at line 1974 of file z3py.py.

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

Referenced by And(), and Or().

◆ _is_algebraic()

_is_algebraic ( ctx,
a )
protected

Definition at line 2871 of file z3py.py.

2871def _is_algebraic(ctx, a):
2872 return Z3_is_algebraic_number(ctx.ref(), a)
2873
2874
bool Z3_API Z3_is_algebraic_number(Z3_context c, Z3_ast a)
Return true if the given AST is a real algebraic number.

Referenced by _to_expr_ref(), and is_algebraic_value().

◆ _is_int()

_is_int ( v)
protected

Definition at line 76 of file z3py.py.

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

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

2867def _is_numeral(ctx, a):
2868 return Z3_is_numeral_ast(ctx.ref(), a)
2869
2870
bool Z3_API Z3_is_numeral_ast(Z3_context c, Z3_ast a)

Referenced by _to_expr_ref(), is_bv_value(), is_int_value(), and is_rational_value().

◆ _mk_bin()

_mk_bin ( f,
a,
b )
protected

Definition at line 1531 of file z3py.py.

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

Referenced by ArithRef.__add__(), ArithRef.__mul__(), ArithRef.__radd__(), ArithRef.__rmul__(), ArithRef.__rsub__(), and ArithRef.__sub__().

◆ _mk_fp_bin()

_mk_fp_bin ( f,
rm,
a,
b,
ctx )
protected

Definition at line 10535 of file z3py.py.

10535def _mk_fp_bin(f, rm, a, b, ctx):
10536 ctx = _get_ctx(ctx)
10537 [a, b] = _coerce_fp_expr_list([a, b], ctx)
10538 if z3_debug():
10539 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
10540 _z3_assert(is_fp(a) or is_fp(b), "Second or third argument must be a Z3 floating-point expression")
10541 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast()), ctx)
10542
10543

◆ _mk_fp_bin_norm()

_mk_fp_bin_norm ( f,
a,
b,
ctx )
protected

Definition at line 10544 of file z3py.py.

10544def _mk_fp_bin_norm(f, a, b, ctx):
10545 ctx = _get_ctx(ctx)
10546 [a, b] = _coerce_fp_expr_list([a, b], ctx)
10547 if z3_debug():
10548 _z3_assert(is_fp(a) or is_fp(b), "First or second argument must be a Z3 floating-point expression")
10549 return FPRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
10550
10551

◆ _mk_fp_bin_pred()

_mk_fp_bin_pred ( f,
a,
b,
ctx )
protected

Definition at line 10552 of file z3py.py.

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

◆ _mk_fp_tern()

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

Definition at line 10560 of file z3py.py.

10560def _mk_fp_tern(f, rm, a, b, c, ctx):
10561 ctx = _get_ctx(ctx)
10562 [a, b, c] = _coerce_fp_expr_list([a, b, c], ctx)
10563 if z3_debug():
10564 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
10565 _z3_assert(is_fp(a) or is_fp(b) or is_fp(
10566 c), "Second, third or fourth argument must be a Z3 floating-point expression")
10567 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
10568
10569

◆ _mk_fp_unary()

_mk_fp_unary ( f,
rm,
a,
ctx )
protected

Definition at line 10518 of file z3py.py.

10518def _mk_fp_unary(f, rm, a, ctx):
10519 ctx = _get_ctx(ctx)
10520 [a] = _coerce_fp_expr_list([a], ctx)
10521 if z3_debug():
10522 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
10523 _z3_assert(is_fp(a), "Second argument must be a Z3 floating-point expression")
10524 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast()), ctx)
10525
10526

◆ _mk_fp_unary_pred()

_mk_fp_unary_pred ( f,
a,
ctx )
protected

Definition at line 10527 of file z3py.py.

10527def _mk_fp_unary_pred(f, a, ctx):
10528 ctx = _get_ctx(ctx)
10529 [a] = _coerce_fp_expr_list([a], ctx)
10530 if z3_debug():
10531 _z3_assert(is_fp(a), "First argument must be a Z3 floating-point expression")
10532 return BoolRef(f(ctx.ref(), a.as_ast()), ctx)
10533
10534

◆ _mk_quantifier()

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

Definition at line 2330 of file z3py.py.

2330def _mk_quantifier(is_forall, vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2331 if z3_debug():
2332 _z3_assert(is_bool(body) or is_app(vs) or (len(vs) > 0 and is_app(vs[0])), "Z3 expression expected")
2333 _z3_assert(is_const(vs) or (len(vs) > 0 and all([is_const(v) for v in vs])), "Invalid bounded variable(s)")
2334 _z3_assert(all([is_pattern(a) or is_expr(a) for a in patterns]), "Z3 patterns expected")
2335 _z3_assert(all([is_expr(p) for p in no_patterns]), "no patterns are Z3 expressions")
2336 if is_app(vs):
2337 ctx = vs.ctx
2338 vs = [vs]
2339 else:
2340 ctx = vs[0].ctx
2341 if not is_expr(body):
2342 body = BoolVal(body, ctx)
2343 num_vars = len(vs)
2344 if num_vars == 0:
2345 return body
2346 _vs = (Ast * num_vars)()
2347 for i in range(num_vars):
2348 # TODO: Check if is constant
2349 _vs[i] = vs[i].as_ast()
2350 patterns = [_to_pattern(p) for p in patterns]
2351 num_pats = len(patterns)
2352 _pats = (Pattern * num_pats)()
2353 for i in range(num_pats):
2354 _pats[i] = patterns[i].ast
2355 _no_pats, num_no_pats = _to_ast_array(no_patterns)
2356 qid = to_symbol(qid, ctx)
2357 skid = to_symbol(skid, ctx)
2358 return QuantifierRef(Z3_mk_quantifier_const_ex(ctx.ref(), is_forall, weight, qid, skid,
2359 num_vars, _vs,
2360 num_pats, _pats,
2361 num_no_pats, _no_pats,
2362 body.as_ast()), ctx)
2363
2364
Z3_ast Z3_API Z3_mk_quantifier_const_ex(Z3_context c, bool is_forall, unsigned weight, Z3_symbol quantifier_id, Z3_symbol skolem_id, unsigned num_bound, Z3_app const bound[], unsigned num_patterns, Z3_pattern const patterns[], unsigned num_no_patterns, Z3_ast const no_patterns[], Z3_ast body)
Create a universal or existential quantifier using a list of constants that will form the set of boun...

Referenced by Exists(), and ForAll().

◆ _or_else()

_or_else ( t1,
t2,
ctx = None )
protected

Definition at line 8643 of file z3py.py.

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

9334def _pb_args_coeffs(args, default_ctx=None):
9335 args = _get_args_ast_list(args)
9336 if len(args) == 0:
9337 return _get_ctx(default_ctx), 0, (Ast * 0)(), (ctypes.c_int * 0)()
9338 args = [_reorder_pb_arg(arg) for arg in args]
9339 args, coeffs = zip(*args)
9340 if z3_debug():
9341 _z3_assert(len(args) > 0, "Non empty list of arguments expected")
9342 ctx = _ctx_from_ast_arg_list(args)
9343 if z3_debug():
9344 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
9345 args = _coerce_expr_list(args, ctx)
9346 _args, sz = _to_ast_array(args)
9347 _coeffs = (ctypes.c_int * len(coeffs))()
9348 for i in range(len(coeffs)):
9349 _z3_check_cint_overflow(coeffs[i], "coefficient")
9350 _coeffs[i] = coeffs[i]
9351 return ctx, sz, _args, _coeffs, args
9352
9353

◆ _probe_and()

_probe_and ( args,
ctx )
protected

Definition at line 9058 of file z3py.py.

9058def _probe_and(args, ctx):
9059 return _probe_nary(Z3_probe_and, args, ctx)
9060
9061

Referenced by And().

◆ _probe_nary()

_probe_nary ( f,
args,
ctx )
protected

Definition at line 9048 of file z3py.py.

9048def _probe_nary(f, args, ctx):
9049 if z3_debug():
9050 _z3_assert(len(args) > 0, "At least one argument expected")
9051 num = len(args)
9052 r = _to_probe(args[0], ctx)
9053 for i in range(num - 1):
9054 r = Probe(f(ctx.ref(), r.probe, _to_probe(args[i + 1], ctx).probe), ctx)
9055 return r
9056
9057

◆ _probe_or()

_probe_or ( args,
ctx )
protected

Definition at line 9062 of file z3py.py.

9062def _probe_or(args, ctx):
9063 return _probe_nary(Z3_probe_or, args, ctx)
9064
9065

Referenced by Or().

◆ _prove_html()

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

Definition at line 9525 of file z3py.py.

9525def _prove_html(claim, show=False, **keywords):
9526 """Version of function `prove` that renders HTML."""
9527 if z3_debug():
9528 _z3_assert(is_bool(claim), "Z3 Boolean expression expected")
9529 s = Solver()
9530 s.set(**keywords)
9531 s.add(Not(claim))
9532 if show:
9533 print(s)
9534 r = s.check()
9535 if r == unsat:
9536 print("<b>proved</b>")
9537 elif r == unknown:
9538 print("<b>failed to prove</b>")
9539 print(s.model())
9540 else:
9541 print("<b>counterexample</b>")
9542 print(s.model())
9543
9544

◆ _py2expr()

_py2expr ( a,
ctx = None )
protected

Definition at line 3272 of file z3py.py.

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

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

◆ _reduce()

_reduce ( func,
sequence,
initial )
protected

Definition at line 1326 of file z3py.py.

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

Referenced by _coerce_expr_list().

◆ _reorder_pb_arg()

_reorder_pb_arg ( arg)
protected

Definition at line 9327 of file z3py.py.

9327def _reorder_pb_arg(arg):
9328 a, b = arg
9329 if not _is_int(b) and _is_int(a):
9330 return b, a
9331 return arg
9332
9333

◆ _solve_html()

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

Definition at line 9476 of file z3py.py.

9476def _solve_html(*args, **keywords):
9477 """Version of function `solve` that renders HTML output."""
9478 show = keywords.pop("show", False)
9479 s = Solver()
9480 s.set(**keywords)
9481 s.add(*args)
9482 if show:
9483 print("<b>Problem:</b>")
9484 print(s)
9485 r = s.check()
9486 if r == unsat:
9487 print("<b>no solution</b>")
9488 elif r == unknown:
9489 print("<b>failed to solve</b>")
9490 try:
9491 print(s.model())
9492 except Z3Exception:
9493 return
9494 else:
9495 if show:
9496 print("<b>Solution:</b>")
9497 print(s.model())
9498
9499

◆ _solve_using_html()

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

Definition at line 9500 of file z3py.py.

9500def _solve_using_html(s, *args, **keywords):
9501 """Version of function `solve_using` that renders HTML."""
9502 show = keywords.pop("show", False)
9503 if z3_debug():
9504 _z3_assert(isinstance(s, Solver), "Solver object expected")
9505 s.set(**keywords)
9506 s.add(*args)
9507 if show:
9508 print("<b>Problem:</b>")
9509 print(s)
9510 r = s.check()
9511 if r == unsat:
9512 print("<b>no solution</b>")
9513 elif r == unknown:
9514 print("<b>failed to solve</b>")
9515 try:
9516 print(s.model())
9517 except Z3Exception:
9518 return
9519 else:
9520 if show:
9521 print("<b>Solution:</b>")
9522 print(s.model())
9523
9524

◆ _sort()

SortRef _sort ( Context ctx,
Any a )
protected

Definition at line 726 of file z3py.py.

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

◆ _sort_kind()

_sort_kind ( ctx,
s )
protected

Sorts.

Definition at line 586 of file z3py.py.

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

Referenced by _to_sort_ref().

◆ _symbol2py()

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

Definition at line 140 of file z3py.py.

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

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

◆ _to_ast_array()

_to_ast_array ( args)
protected

Definition at line 554 of file z3py.py.

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

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

◆ _to_ast_ref()

_to_ast_ref ( a,
ctx )
protected

Definition at line 570 of file z3py.py.

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

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

◆ _to_expr_ref()

_to_expr_ref ( a,
ctx )
protected

Definition at line 1221 of file z3py.py.

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

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

◆ _to_float_str()

_to_float_str ( val,
exp = 0 )
protected

Definition at line 10280 of file z3py.py.

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

◆ _to_func_decl_array()

_to_func_decl_array ( args)
protected

Definition at line 546 of file z3py.py.

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

◆ _to_func_decl_ref()

_to_func_decl_ref ( a,
ctx )
protected

Definition at line 962 of file z3py.py.

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

Referenced by _to_ast_ref().

◆ _to_goal()

_to_goal ( a)
protected

Definition at line 8619 of file z3py.py.

8619def _to_goal(a):
8620 if isinstance(a, BoolRef):
8621 goal = Goal(ctx=a.ctx)
8622 goal.add(a)
8623 return goal
8624 else:
8625 return a
8626
8627

◆ _to_int_str()

_to_int_str ( val)
protected

Definition at line 3321 of file z3py.py.

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

Referenced by BitVecVal(), and IntVal().

◆ _to_param_value()

_to_param_value ( val)
protected

Definition at line 178 of file z3py.py.

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

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

◆ _to_pattern()

_to_pattern ( arg)
protected

Definition at line 2108 of file z3py.py.

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

Referenced by _mk_quantifier().

◆ _to_probe()

_to_probe ( p,
ctx = None )
protected

Definition at line 9002 of file z3py.py.

9002def _to_probe(p, ctx=None):
9003 if is_probe(p):
9004 return p
9005 else:
9006 return Probe(p, ctx)
9007
9008

◆ _to_ref_array()

_to_ref_array ( ref,
args )
protected

Definition at line 562 of file z3py.py.

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

◆ _to_sort_ref()

_to_sort_ref ( s,
ctx )
protected

Definition at line 695 of file z3py.py.

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

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

◆ _to_tactic()

_to_tactic ( t,
ctx = None )
protected

Definition at line 8628 of file z3py.py.

8628def _to_tactic(t, ctx=None):
8629 if isinstance(t, Tactic):
8630 return t
8631 else:
8632 return Tactic(t, ctx)
8633
8634

◆ _valid_accessor()

_valid_accessor ( acc)
protected

Datatypes.

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

Definition at line 5205 of file z3py.py.

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

Referenced by Datatype.declare_core().

◆ _z3_assert()

_z3_assert ( cond,
msg )
protected

Definition at line 113 of file z3py.py.

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

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

◆ _z3_check_cint_overflow()

_z3_check_cint_overflow ( n,
name )
protected

Definition at line 118 of file z3py.py.

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

◆ Abs()

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

Definition at line 9286 of file z3py.py.

9286def Abs(arg):
9287 """Create the absolute value of an arithmetic expression"""
9288 return If(arg > 0, arg, -arg)
9289
9290

◆ AllChar()

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

Definition at line 11723 of file z3py.py.

11723def AllChar(regex_sort, ctx=None):
11724 """Create a regular expression that accepts all single character strings
11725 """
11726 return ReRef(Z3_mk_re_allchar(regex_sort.ctx_ref(), regex_sort.ast), regex_sort.ctx)
11727
11728# Special Relations
11729
11730
Z3_ast Z3_API Z3_mk_re_allchar(Z3_context c, Z3_sort regex_sort)
Create a regular expression that accepts all singleton sequences of the regular expression sort.

◆ And()

And ( * args)
Create a Z3 and-expression or and-probe.

>>> p, q, r = Bools('p q r')
>>> And(p, q, r)
And(p, q, r)
>>> P = BoolVector('p', 5)
>>> And(P)
And(p__0, p__1, p__2, p__3, p__4)

Definition at line 1982 of file z3py.py.

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

Referenced by BoolRef.__and__(), and Goal.as_expr().

◆ AndThen()

AndThen ( * ts,
** ks )
Return a tactic that applies the tactics in `*ts` in sequence.

>>> x, y = Ints('x y')
>>> t = AndThen(Tactic('simplify'), Tactic('solve-eqs'))
>>> t(And(x == 0, y > x + 1))
[[Not(y <= 1)]]
>>> t(And(x == 0, y > x + 1)).as_expr()
Not(y <= 1)

Definition at line 8651 of file z3py.py.

8651def AndThen(*ts, **ks):
8652 """Return a tactic that applies the tactics in `*ts` in sequence.
8653
8654 >>> x, y = Ints('x y')
8655 >>> t = AndThen(Tactic('simplify'), Tactic('solve-eqs'))
8656 >>> t(And(x == 0, y > x + 1))
8657 [[Not(y <= 1)]]
8658 >>> t(And(x == 0, y > x + 1)).as_expr()
8659 Not(y <= 1)
8660 """
8661 if z3_debug():
8662 _z3_assert(len(ts) >= 2, "At least two arguments expected")
8663 ctx = ks.get("ctx", None)
8664 num = len(ts)
8665 r = ts[0]
8666 for i in range(num - 1):
8667 r = _and_then(r, ts[i + 1], ctx)
8668 return r
8669
8670

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

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

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

4908def Array(name, *sorts):
4909 """Return an array constant named `name` with the given domain and range sorts.
4910
4911 >>> a = Array('a', IntSort(), IntSort())
4912 >>> a.sort()
4913 Array(Int, Int)
4914 >>> a[0]
4915 a[0]
4916 """
4917 s = ArraySort(sorts)
4918 ctx = s.ctx
4919 return ArrayRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), s.ast), ctx)
4920
4921
Z3_ast Z3_API Z3_mk_const(Z3_context c, Z3_symbol s, Z3_sort ty)
Declare and create a constant.

◆ ArraySort()

ArraySort ( * sig)
Return the Z3 array sort with the given domain and range sorts.

>>> A = ArraySort(IntSort(), BoolSort())
>>> A
Array(Int, Bool)
>>> A.domain()
Int
>>> A.range()
Bool
>>> AA = ArraySort(IntSort(), A)
>>> AA
Array(Int, Array(Int, Bool))

Definition at line 4875 of file z3py.py.

4875def ArraySort(*sig):
4876 """Return the Z3 array sort with the given domain and range sorts.
4877
4878 >>> A = ArraySort(IntSort(), BoolSort())
4879 >>> A
4880 Array(Int, Bool)
4881 >>> A.domain()
4882 Int
4883 >>> A.range()
4884 Bool
4885 >>> AA = ArraySort(IntSort(), A)
4886 >>> AA
4887 Array(Int, Array(Int, Bool))
4888 """
4889 sig = _get_args(sig)
4890 if z3_debug():
4891 _z3_assert(len(sig) > 1, "At least two arguments expected")
4892 arity = len(sig) - 1
4893 r = sig[arity]
4894 d = sig[0]
4895 if z3_debug():
4896 for s in sig:
4897 _z3_assert(is_sort(s), "Z3 sort expected")
4898 _z3_assert(s.ctx == r.ctx, "Context mismatch")
4899 ctx = d.ctx
4900 if len(sig) == 2:
4901 return ArraySortRef(Z3_mk_array_sort(ctx.ref(), d.ast, r.ast), ctx)
4902 dom = (Sort * arity)()
4903 for i in range(arity):
4904 dom[i] = sig[i].ast
4905 return ArraySortRef(Z3_mk_array_sort_n(ctx.ref(), arity, dom, r.ast), ctx)
4906
4907
Z3_sort Z3_API Z3_mk_array_sort_n(Z3_context c, unsigned n, Z3_sort const *domain, Z3_sort range)
Create an array type with N arguments.
Z3_sort Z3_API Z3_mk_array_sort(Z3_context c, Z3_sort domain, Z3_sort range)
Create an array type.

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

◆ AtLeast()

AtLeast ( * args)
Create an at-least Pseudo-Boolean k constraint.

>>> a, b, c = Bools('a b c')
>>> f = AtLeast(a, b, c, 2)

Definition at line 9309 of file z3py.py.

9309def AtLeast(*args):
9310 """Create an at-least Pseudo-Boolean k constraint.
9311
9312 >>> a, b, c = Bools('a b c')
9313 >>> f = AtLeast(a, b, c, 2)
9314 """
9315 args = _get_args(args)
9316 if z3_debug():
9317 _z3_assert(len(args) > 1, "Non empty list of arguments expected")
9318 ctx = _ctx_from_ast_arg_list(args)
9319 if z3_debug():
9320 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
9321 args1 = _coerce_expr_list(args[:-1], ctx)
9322 k = args[-1]
9323 _args, sz = _to_ast_array(args1)
9324 return BoolRef(Z3_mk_atleast(ctx.ref(), sz, _args, k), ctx)
9325
9326
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 9291 of file z3py.py.

9291def AtMost(*args):
9292 """Create an at-most Pseudo-Boolean k constraint.
9293
9294 >>> a, b, c = Bools('a b c')
9295 >>> f = AtMost(a, b, c, 2)
9296 """
9297 args = _get_args(args)
9298 if z3_debug():
9299 _z3_assert(len(args) > 1, "Non empty list of arguments expected")
9300 ctx = _ctx_from_ast_arg_list(args)
9301 if z3_debug():
9302 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
9303 args1 = _coerce_expr_list(args[:-1], ctx)
9304 k = args[-1]
9305 _args, sz = _to_ast_array(args1)
9306 return BoolRef(Z3_mk_atmost(ctx.ref(), sz, _args, k), ctx)
9307
9308
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 4189 of file z3py.py.

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

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

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

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

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

4172def BitVecVal(val, bv, ctx=None):
4173 """Return a bit-vector value with the given number of bits. If `ctx=None`, then the global context is used.
4174
4175 >>> v = BitVecVal(10, 32)
4176 >>> v
4177 10
4178 >>> print("0x%.8x" % v.as_long())
4179 0x0000000a
4180 """
4181 if is_bv_sort(bv):
4182 ctx = bv.ctx
4183 return BitVecNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), bv.ast), ctx)
4184 else:
4185 ctx = _get_ctx(ctx)
4186 return BitVecNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), BitVecSort(bv, ctx).ast), ctx)
4187
4188
Z3_ast Z3_API Z3_mk_numeral(Z3_context c, Z3_string numeral, Z3_sort ty)
Create a numeral of a given sort.

◆ Bool()

Bool ( name,
ctx = None )
Return a Boolean constant named `name`. If `ctx=None`, then the global context is used.

>>> p = Bool('p')
>>> q = Bool('q')
>>> And(p, q)
And(p, q)

Definition at line 1861 of file z3py.py.

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

Referenced by Solver.assert_and_track(), Bools(), and BoolVector().

◆ Bools()

Bools ( names,
ctx = None )
Return a tuple of Boolean constants.

`names` is a single string containing all names separated by blank spaces.
If `ctx=None`, then the global context is used.

>>> p, q, r = Bools('p q r')
>>> And(p, Or(q, r))
And(p, Or(q, r))

Definition at line 1873 of file z3py.py.

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

◆ BoolSort()

BoolSort ( ctx = None)
Return the Boolean Z3 sort. If `ctx=None`, then the global context is used.

>>> BoolSort()
Bool
>>> p = Const('p', BoolSort())
>>> is_bool(p)
True
>>> r = Function('r', IntSort(), IntSort(), BoolSort())
>>> r(0, 1)
r(0, 1)
>>> is_bool(r(0, 1))
True

Definition at line 1824 of file z3py.py.

1824def BoolSort(ctx=None):
1825 """Return the Boolean Z3 sort. If `ctx=None`, then the global context is used.
1826
1827 >>> BoolSort()
1828 Bool
1829 >>> p = Const('p', BoolSort())
1830 >>> is_bool(p)
1831 True
1832 >>> r = Function('r', IntSort(), IntSort(), BoolSort())
1833 >>> r(0, 1)
1834 r(0, 1)
1835 >>> is_bool(r(0, 1))
1836 True
1837 """
1838 ctx = _get_ctx(ctx)
1839 return BoolSortRef(Z3_mk_bool_sort(ctx.ref()), ctx)
1840
1841
Z3_sort Z3_API Z3_mk_bool_sort(Z3_context c)
Create the Boolean type.

Referenced by Goal.assert_exprs(), Solver.assert_exprs(), Bool(), Solver.check(), FreshBool(), If(), Implies(), Not(), SetSort(), and Xor().

◆ BoolVal()

BoolVal ( val,
ctx = None )
Return the Boolean value `True` or `False`. If `ctx=None`, then the global context is used.

>>> BoolVal(True)
True
>>> is_true(BoolVal(True))
True
>>> is_true(True)
False
>>> is_false(BoolVal(False))
True

Definition at line 1842 of file z3py.py.

1842def BoolVal(val, ctx=None):
1843 """Return the Boolean value `True` or `False`. If `ctx=None`, then the global context is used.
1844
1845 >>> BoolVal(True)
1846 True
1847 >>> is_true(BoolVal(True))
1848 True
1849 >>> is_true(True)
1850 False
1851 >>> is_false(BoolVal(False))
1852 True
1853 """
1854 ctx = _get_ctx(ctx)
1855 if val:
1856 return BoolRef(Z3_mk_true(ctx.ref()), ctx)
1857 else:
1858 return BoolRef(Z3_mk_false(ctx.ref()), ctx)
1859
1860
Z3_ast Z3_API Z3_mk_true(Z3_context c)
Create an AST node representing true.
Z3_ast Z3_API Z3_mk_false(Z3_context c)
Create an AST node representing false.

Referenced by _mk_quantifier(), _py2expr(), and Goal.as_expr().

◆ BoolVector()

BoolVector ( prefix,
sz,
ctx = None )
Return a list of Boolean constants of size `sz`.

The constants are named using the given prefix.
If `ctx=None`, then the global context is used.

>>> P = BoolVector('p', 3)
>>> P
[p__0, p__1, p__2]
>>> And(P)
And(p__0, p__1, p__2)

Definition at line 1889 of file z3py.py.

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

◆ BV2Int()

BV2Int ( a,
is_signed = False )
Return the Z3 expression BV2Int(a).

>>> b = BitVec('b', 3)
>>> BV2Int(b).sort()
Int
>>> x = Int('x')
>>> x > BV2Int(b)
x > BV2Int(b)
>>> x > BV2Int(b, is_signed=False)
x > BV2Int(b)
>>> x > BV2Int(b, is_signed=True)
x > If(b < 0, BV2Int(b) - 8, BV2Int(b))
>>> solve(x > BV2Int(b), b == 1, x < 3)
[x = 2, b = 1]

Definition at line 4125 of file z3py.py.

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

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

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

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

4683def BVMulNoUnderflow(a, b):
4684 """A predicate the determines that bit-vector signed multiplication does not underflow"""
4685 _check_bv_args(a, b)
4686 a, b = _coerce_exprs(a, b)
4687 return BoolRef(Z3_mk_bvmul_no_underflow(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
4688
4689
Z3_ast Z3_API Z3_mk_bvmul_no_underflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed multiplication of t1 and t2 does not underflo...

◆ BVRedAnd()

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

Definition at line 4620 of file z3py.py.

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

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

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

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

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

4655def BVSubNoUnderflow(a, b, signed):
4656 """A predicate the determines that bit-vector subtraction does not underflow"""
4657 _check_bv_args(a, b)
4658 a, b = _coerce_exprs(a, b)
4659 return BoolRef(Z3_mk_bvsub_no_underflow(a.ctx_ref(), a.as_ast(), b.as_ast(), signed), a.ctx)
4660
4661
Z3_ast Z3_API Z3_mk_bvsub_no_underflow(Z3_context c, Z3_ast t1, Z3_ast t2, bool is_signed)
Create a predicate that checks that the bit-wise subtraction of t1 and t2 does not underflow.

◆ Cbrt()

Cbrt ( a,
ctx = None )
 Return a Z3 expression which represents the cubic root of a.

>>> x = Real('x')
>>> Cbrt(x)
x**(1/3)

Definition at line 3571 of file z3py.py.

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

◆ CharFromBv()

CharFromBv ( bv)

Definition at line 11223 of file z3py.py.

11223def CharFromBv(bv):
11224 if not is_expr(bv):
11225 raise Z3Exception("Bit-vector expression needed")
11226 return _to_expr_ref(Z3_mk_char_from_bv(bv.ctx_ref(), bv.as_ast()), bv.ctx)
11227
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 11236 of file z3py.py.

11236def CharIsDigit(ch, ctx=None):
11237 ch = _coerce_char(ch, ctx)
11238 return ch.is_digit()
11239

◆ CharSort()

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

Definition at line 11119 of file z3py.py.

11119def CharSort(ctx=None):
11120 """Create a character sort
11121 >>> ch = CharSort()
11122 >>> print(ch)
11123 Char
11124 """
11125 ctx = _get_ctx(ctx)
11126 return CharSortRef(Z3_mk_char_sort(ctx.ref()), ctx)
11127
11128
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 11228 of file z3py.py.

11228def CharToBv(ch, ctx=None):
11229 ch = _coerce_char(ch, ctx)
11230 return ch.to_bv()
11231

◆ CharToInt()

CharToInt ( ch,
ctx = None )

Definition at line 11232 of file z3py.py.

11232def CharToInt(ch, ctx=None):
11233 ch = _coerce_char(ch, ctx)
11234 return ch.to_int()
11235

◆ CharVal()

CharVal ( ch,
ctx = None )

Definition at line 11215 of file z3py.py.

11215def CharVal(ch, ctx=None):
11216 ctx = _get_ctx(ctx)
11217 if isinstance(ch, str):
11218 ch = ord(ch)
11219 if not isinstance(ch, int):
11220 raise Z3Exception("character value should be an ordinal")
11221 return _to_expr_ref(Z3_mk_char(ctx.ref(), ch), ctx)
11222
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 11665 of file z3py.py.

11665def Complement(re):
11666 """Create the complement regular expression."""
11667 return ReRef(Z3_mk_re_complement(re.ctx_ref(), re.as_ast()), re.ctx)
11668
11669
Z3_ast Z3_API Z3_mk_re_complement(Z3_context c, Z3_ast re)
Create the complement of the regular language re.

◆ Concat()

Concat ( * args)
Create a Z3 bit-vector concatenation expression.

>>> v = BitVecVal(1, 4)
>>> Concat(v, v+1, v)
Concat(Concat(1, 1 + 1), 1)
>>> simplify(Concat(v, v+1, v))
289
>>> print("%.3x" % simplify(Concat(v, v+1, v)).as_long())
121

Definition at line 4234 of file z3py.py.

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

9108def Cond(p, t1, t2, ctx=None):
9109 """Return a tactic that applies tactic `t1` to a goal if probe `p` evaluates to true, and `t2` otherwise.
9110
9111 >>> t = Cond(Probe('is-qfnra'), Tactic('qfnra'), Tactic('smt'))
9112 """
9113 p = _to_probe(p, ctx)
9114 t1 = _to_tactic(t1, ctx)
9115 t2 = _to_tactic(t2, ctx)
9116 return Tactic(Z3_tactic_cond(t1.ctx.ref(), p.probe, t1.tactic, t2.tactic), t1.ctx)
9117
Z3_tactic Z3_API Z3_tactic_cond(Z3_context c, Z3_probe p, Z3_tactic t1, Z3_tactic t2)
Return a tactic that applies t1 to a given goal if the probe p evaluates to true, and t2 if p evaluat...

Referenced by If().

◆ Const()

Const ( name,
sort )
Create a constant of the given sort.

>>> Const('x', IntSort())
x

Definition at line 1540 of file z3py.py.

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

Referenced by Consts().

◆ Consts()

Consts ( names,
sort )
Create several constants of the given sort.

`names` is a string containing the names of all constants to be created.
Blank spaces separate the names of different constants.

>>> x, y, z = Consts('x y z', IntSort())
>>> x + y + z
x + y + z

Definition at line 1552 of file z3py.py.

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

◆ Contains()

Contains ( a,
b )
Check if 'a' contains 'b'
>>> s1 = Contains("abc", "ab")
>>> simplify(s1)
True
>>> s2 = Contains("abc", "bc")
>>> simplify(s2)
True
>>> x, y, z = Strings('x y z')
>>> s3 = Contains(Concat(x,y,z), y)
>>> simplify(s3)
True

Definition at line 11410 of file z3py.py.

11410def Contains(a, b):
11411 """Check if 'a' contains 'b'
11412 >>> s1 = Contains("abc", "ab")
11413 >>> simplify(s1)
11414 True
11415 >>> s2 = Contains("abc", "bc")
11416 >>> simplify(s2)
11417 True
11418 >>> x, y, z = Strings('x y z')
11419 >>> s3 = Contains(Concat(x,y,z), y)
11420 >>> simplify(s3)
11421 True
11422 """
11423 ctx = _get_ctx2(a, b)
11424 a = _coerce_seq(a, ctx)
11425 b = _coerce_seq(b, ctx)
11426 return BoolRef(Z3_mk_seq_contains(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
11427
11428
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 5326 of file z3py.py.

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

Referenced by Datatype.create().

◆ DatatypeSort()

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

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

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

Definition at line 5552 of file z3py.py.

5552def DatatypeSort(name, params=None, ctx=None):
5553 """Create a reference to a sort that was declared, or will be declared, as a recursive datatype.
5554
5555 Args:
5556 name: name of the datatype sort
5557 params: optional list/tuple of sort parameters for parametric datatypes
5558 ctx: Z3 context (optional)
5559
5560 Example:
5561 >>> # Non-parametric datatype
5562 >>> TreeRef = DatatypeSort('Tree')
5563 >>> # Parametric datatype with one parameter
5564 >>> ListIntRef = DatatypeSort('List', [IntSort()])
5565 >>> # Parametric datatype with multiple parameters
5566 >>> PairRef = DatatypeSort('Pair', [IntSort(), BoolSort()])
5567 """
5568 ctx = _get_ctx(ctx)
5569 if params is None or len(params) == 0:
5570 return DatatypeSortRef(Z3_mk_datatype_sort(ctx.ref(), to_symbol(name, ctx), 0, (Sort * 0)()), ctx)
5571 else:
5572 _params = (Sort * len(params))()
5573 for i in range(len(params)):
5574 _params[i] = params[i].ast
5575 return DatatypeSortRef(Z3_mk_datatype_sort(ctx.ref(), to_symbol(name, ctx), len(params), _params), ctx)
5576
Z3_sort Z3_API Z3_mk_datatype_sort(Z3_context c, Z3_symbol name, unsigned num_params, Z3_sort const params[])
create a forward reference to a recursive datatype being declared. The forward reference can be used ...

◆ DeclareSort()

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

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

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

Definition at line 730 of file z3py.py.

730def DeclareSort(name, ctx= None) -> SortRef:
731 """Create a new uninterpreted sort named `name`.
732
733 If `ctx=None`, then the new sort is declared in the global Z3Py context.
734
735 >>> A = DeclareSort('A')
736 >>> a = Const('a', A)
737 >>> b = Const('b', A)
738 >>> a.sort() == A
739 True
740 >>> b.sort() == A
741 True
742 >>> a == b
743 a == b
744 """
745 ctx = _get_ctx(ctx)
746 return SortRef(Z3_mk_uninterpreted_sort(ctx.ref(), to_symbol(name, ctx)), ctx)
747
Z3_sort Z3_API Z3_mk_uninterpreted_sort(Z3_context c, Z3_symbol s)
Create a free (uninterpreted) type using the given name (symbol).

◆ DeclareTypeVar()

DeclareTypeVar ( name,
ctx = None )
Create a new type variable named `name`.

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

Definition at line 758 of file z3py.py.

758def DeclareTypeVar(name, ctx=None):
759 """Create a new type variable named `name`.
760
761 If `ctx=None`, then the new sort is declared in the global Z3Py context.
762
763 """
764 ctx = _get_ctx(ctx)
765 return TypeVarRef(Z3_mk_type_variable(ctx.ref(), to_symbol(name, ctx)), ctx)
766
767
Z3_sort Z3_API Z3_mk_type_variable(Z3_context c, Z3_symbol s)
Create a type variable.

◆ Default()

Default ( a)
 Return a default value for array expression.
>>> b = K(IntSort(), 1)
>>> prove(Default(b) == 1)
proved

Definition at line 4954 of file z3py.py.

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

◆ describe_probes()

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

Definition at line 9029 of file z3py.py.

9029def describe_probes():
9030 """Display a (tabular) description of all available probes in Z3."""
9031 if in_html_mode():
9032 even = True
9033 print('<table border="1" cellpadding="2" cellspacing="0">')
9034 for p in probes():
9035 if even:
9036 print('<tr style="background-color:#CFCFCF">')
9037 even = False
9038 else:
9039 print("<tr>")
9040 even = True
9041 print("<td>%s</td><td>%s</td></tr>" % (p, insert_line_breaks(probe_description(p), 40)))
9042 print("</table>")
9043 else:
9044 for p in probes():
9045 print("%s : %s" % (p, probe_description(p)))
9046
9047

◆ describe_tactics()

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

Definition at line 8823 of file z3py.py.

8823def describe_tactics():
8824 """Display a (tabular) description of all available tactics in Z3."""
8825 if in_html_mode():
8826 even = True
8827 print('<table border="1" cellpadding="2" cellspacing="0">')
8828 for t in tactics():
8829 if even:
8830 print('<tr style="background-color:#CFCFCF">')
8831 even = False
8832 else:
8833 print("<tr>")
8834 even = True
8835 print("<td>%s</td><td>%s</td></tr>" % (t, insert_line_breaks(tactic_description(t), 40)))
8836 print("</table>")
8837 else:
8838 for t in tactics():
8839 print("%s : %s" % (t, tactic_description(t)))
8840
8841

◆ deserialize()

deserialize ( st)
inverse function to the serialize method on ExprRef.
It is made available to make it easier for users to serialize expressions back and forth between
strings. Solvers can be serialized using the 'sexpr()' method.

Definition at line 1207 of file z3py.py.

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

◆ Diff()

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

Definition at line 11715 of file z3py.py.

11715def Diff(a, b, ctx=None):
11716 """Create the difference regular expression
11717 """
11718 if z3_debug():
11719 _z3_assert(is_expr(a), "expression expected")
11720 _z3_assert(is_expr(b), "expression expected")
11721 return ReRef(Z3_mk_re_diff(a.ctx_ref(), a.ast, b.ast), a.ctx)
11722
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 5589 of file z3py.py.

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

◆ Distinct()

Distinct ( * args)
Create a Z3 distinct expression.

>>> x = Int('x')
>>> y = Int('y')
>>> Distinct(x, y)
x != y
>>> z = Int('z')
>>> Distinct(x, y, z)
Distinct(x, y, z)
>>> simplify(Distinct(x, y, z))
Distinct(x, y, z)
>>> simplify(Distinct(x, y, z), blast_distinct=True)
And(Not(x == y), Not(x == z), Not(y == z))

Definition at line 1507 of file z3py.py.

1507def Distinct(*args):
1508 """Create a Z3 distinct expression.
1509
1510 >>> x = Int('x')
1511 >>> y = Int('y')
1512 >>> Distinct(x, y)
1513 x != y
1514 >>> z = Int('z')
1515 >>> Distinct(x, y, z)
1516 Distinct(x, y, z)
1517 >>> simplify(Distinct(x, y, z))
1518 Distinct(x, y, z)
1519 >>> simplify(Distinct(x, y, z), blast_distinct=True)
1520 And(Not(x == y), Not(x == z), Not(y == z))
1521 """
1522 args = _get_args(args)
1523 ctx = _ctx_from_ast_arg_list(args)
1524 if z3_debug():
1525 _z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
1526 args = _coerce_expr_list(args, ctx)
1527 _args, sz = _to_ast_array(args)
1528 return BoolRef(Z3_mk_distinct(ctx.ref(), sz, _args), ctx)
1529
1530
Z3_ast Z3_API Z3_mk_distinct(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing distinct(args[0], ..., args[num_args-1]).

◆ Empty()

Empty ( s)
Create the empty sequence of the given sort
>>> e = Empty(StringSort())
>>> e2 = StringVal("")
>>> print(e.eq(e2))
True
>>> e3 = Empty(SeqSort(IntSort()))
>>> print(e3)
Empty(Seq(Int))
>>> e4 = Empty(ReSort(SeqSort(IntSort())))
>>> print(e4)
Empty(ReSort(Seq(Int)))

Definition at line 11340 of file z3py.py.

11340def Empty(s):
11341 """Create the empty sequence of the given sort
11342 >>> e = Empty(StringSort())
11343 >>> e2 = StringVal("")
11344 >>> print(e.eq(e2))
11345 True
11346 >>> e3 = Empty(SeqSort(IntSort()))
11347 >>> print(e3)
11348 Empty(Seq(Int))
11349 >>> e4 = Empty(ReSort(SeqSort(IntSort())))
11350 >>> print(e4)
11351 Empty(ReSort(Seq(Int)))
11352 """
11353 if isinstance(s, SeqSortRef):
11354 return SeqRef(Z3_mk_seq_empty(s.ctx_ref(), s.ast), s.ctx)
11355 if isinstance(s, ReSortRef):
11356 return ReRef(Z3_mk_re_empty(s.ctx_ref(), s.ast), s.ctx)
11357 raise Z3Exception("Non-sequence, non-regular expression sort passed to Empty")
11358
11359
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 5090 of file z3py.py.

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

11834def ensure_prop_closures():
11835 global _prop_closures
11836 if _prop_closures is None:
11837 _prop_closures = PropClosures()
11838
11839

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

5601def EnumSort(name, values, ctx=None):
5602 """Return a new enumeration sort named `name` containing the given values.
5603
5604 The result is a pair (sort, list of constants).
5605 Example:
5606 >>> Color, (red, green, blue) = EnumSort('Color', ['red', 'green', 'blue'])
5607 """
5608 if z3_debug():
5609 _z3_assert(isinstance(name, str), "Name must be a string")
5610 _z3_assert(all([isinstance(v, str) for v in values]), "Enumeration sort values must be strings")
5611 _z3_assert(len(values) > 0, "At least one value expected")
5612 ctx = _get_ctx(ctx)
5613 num = len(values)
5614 _val_names = (Symbol * num)()
5615 for i in range(num):
5616 _val_names[i] = to_symbol(values[i], ctx)
5617 _values = (FuncDecl * num)()
5618 _testers = (FuncDecl * num)()
5619 name = to_symbol(name, ctx)
5620 S = DatatypeSortRef(Z3_mk_enumeration_sort(ctx.ref(), name, num, _val_names, _values, _testers), ctx)
5621 V = []
5622 for i in range(num):
5623 V.append(FuncDeclRef(_values[i], ctx))
5624 V = [a() for a in V]
5625 return S, V
5626
Z3_sort Z3_API Z3_mk_enumeration_sort(Z3_context c, Z3_symbol name, unsigned n, Z3_symbol const enum_names[], Z3_func_decl enum_consts[], Z3_func_decl enum_testers[])
Create a enumeration sort.

◆ eq()

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

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

Definition at line 503 of file z3py.py.

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

◆ Exists()

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

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


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

Definition at line 2383 of file z3py.py.

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

◆ Ext()

Ext ( a,
b )
Return extensionality index for one-dimensional arrays.
>> a, b = Consts('a b', SetSort(IntSort()))
>> Ext(a, b)
Ext(a, b)

Definition at line 5043 of file z3py.py.

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

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

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

7997def FiniteDomainSort(name, sz, ctx=None):
7998 """Create a named finite domain sort of a given size sz"""
7999 if not isinstance(name, Symbol):
8000 name = to_symbol(name)
8001 ctx = _get_ctx(ctx)
8002 return FiniteDomainSortRef(Z3_mk_finite_domain_sort(ctx.ref(), name, sz), ctx)
8003
8004
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 8067 of file z3py.py.

8067def FiniteDomainVal(val, sort, ctx=None):
8068 """Return a Z3 finite-domain value. If `ctx=None`, then the global context is used.
8069
8070 >>> s = FiniteDomainSort('S', 256)
8071 >>> FiniteDomainVal(255, s)
8072 255
8073 >>> FiniteDomainVal('100', s)
8074 100
8075 """
8076 if z3_debug():
8077 _z3_assert(is_finite_domain_sort(sort), "Expected finite-domain sort")
8078 ctx = sort.ctx
8079 return FiniteDomainNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), sort.ast), ctx)
8080
8081

◆ Float128()

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

Definition at line 9794 of file z3py.py.

9794def Float128(ctx=None):
9795 """Floating-point 128-bit (quadruple) sort."""
9796 ctx = _get_ctx(ctx)
9797 return FPSortRef(Z3_mk_fpa_sort_128(ctx.ref()), ctx)
9798
9799
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 9758 of file z3py.py.

9758def Float16(ctx=None):
9759 """Floating-point 16-bit (half) sort."""
9760 ctx = _get_ctx(ctx)
9761 return FPSortRef(Z3_mk_fpa_sort_16(ctx.ref()), ctx)
9762
9763
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 9770 of file z3py.py.

9770def Float32(ctx=None):
9771 """Floating-point 32-bit (single) sort."""
9772 ctx = _get_ctx(ctx)
9773 return FPSortRef(Z3_mk_fpa_sort_32(ctx.ref()), ctx)
9774
9775
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 9782 of file z3py.py.

9782def Float64(ctx=None):
9783 """Floating-point 64-bit (double) sort."""
9784 ctx = _get_ctx(ctx)
9785 return FPSortRef(Z3_mk_fpa_sort_64(ctx.ref()), ctx)
9786
9787
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 9788 of file z3py.py.

9788def FloatDouble(ctx=None):
9789 """Floating-point 64-bit (double) sort."""
9790 ctx = _get_ctx(ctx)
9791 return FPSortRef(Z3_mk_fpa_sort_double(ctx.ref()), ctx)
9792
9793
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 9764 of file z3py.py.

9764def FloatHalf(ctx=None):
9765 """Floating-point 16-bit (half) sort."""
9766 ctx = _get_ctx(ctx)
9767 return FPSortRef(Z3_mk_fpa_sort_half(ctx.ref()), ctx)
9768
9769
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 9800 of file z3py.py.

9800def FloatQuadruple(ctx=None):
9801 """Floating-point 128-bit (quadruple) sort."""
9802 ctx = _get_ctx(ctx)
9803 return FPSortRef(Z3_mk_fpa_sort_quadruple(ctx.ref()), ctx)
9804
9805
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 9776 of file z3py.py.

9776def FloatSingle(ctx=None):
9777 """Floating-point 32-bit (single) sort."""
9778 ctx = _get_ctx(ctx)
9779 return FPSortRef(Z3_mk_fpa_sort_single(ctx.ref()), ctx)
9780
9781
Z3_sort Z3_API Z3_mk_fpa_sort_single(Z3_context c)
Create the single-precision (32-bit) FloatingPoint sort.

◆ ForAll()

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

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

>>> f = Function('f', IntSort(), IntSort(), IntSort())
>>> x = Int('x')
>>> y = Int('y')
>>> ForAll([x, y], f(x, y) >= x)
ForAll([x, y], f(x, y) >= x)
>>> ForAll([x, y], f(x, y) >= x, patterns=[ f(x, y) ])
ForAll([x, y], f(x, y) >= x)
>>> ForAll([x, y], f(x, y) >= x, weight=10)
ForAll([x, y], f(x, y) >= x)

Definition at line 2365 of file z3py.py.

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

◆ FP()

FP ( name,
fpsort,
ctx = None )
Return a floating-point constant named `name`.
`fpsort` is the floating-point sort.
If `ctx=None`, then the global context is used.

>>> x  = FP('x', FPSort(8, 24))
>>> is_fp(x)
True
>>> x.ebits()
8
>>> x.sort()
FPSort(8, 24)
>>> word = FPSort(8, 24)
>>> x2 = FP('x', word)
>>> eq(x, x2)
True

Definition at line 10436 of file z3py.py.

10436def FP(name, fpsort, ctx=None):
10437 """Return a floating-point constant named `name`.
10438 `fpsort` is the floating-point sort.
10439 If `ctx=None`, then the global context is used.
10440
10441 >>> x = FP('x', FPSort(8, 24))
10442 >>> is_fp(x)
10443 True
10444 >>> x.ebits()
10445 8
10446 >>> x.sort()
10447 FPSort(8, 24)
10448 >>> word = FPSort(8, 24)
10449 >>> x2 = FP('x', word)
10450 >>> eq(x, x2)
10451 True
10452 """
10453 if isinstance(fpsort, FPSortRef) and ctx is None:
10454 ctx = fpsort.ctx
10455 else:
10456 ctx = _get_ctx(ctx)
10457 return FPRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), fpsort.ast), ctx)
10458
10459

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

10479def fpAbs(a, ctx=None):
10480 """Create a Z3 floating-point absolute value expression.
10481
10482 >>> s = FPSort(8, 24)
10483 >>> rm = RNE()
10484 >>> x = FPVal(1.0, s)
10485 >>> fpAbs(x)
10486 fpAbs(1)
10487 >>> y = FPVal(-20.0, s)
10488 >>> y
10489 -1.25*(2**4)
10490 >>> fpAbs(y)
10491 fpAbs(-1.25*(2**4))
10492 >>> fpAbs(-1.25*(2**4))
10493 fpAbs(-1.25*(2**4))
10494 >>> fpAbs(x).sort()
10495 FPSort(8, 24)
10496 """
10497 ctx = _get_ctx(ctx)
10498 [a] = _coerce_fp_expr_list([a], ctx)
10499 return FPRef(Z3_mk_fpa_abs(ctx.ref(), a.as_ast()), ctx)
10500
10501
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 10570 of file z3py.py.

10570def fpAdd(rm, a, b, ctx=None):
10571 """Create a Z3 floating-point addition expression.
10572
10573 >>> s = FPSort(8, 24)
10574 >>> rm = RNE()
10575 >>> x = FP('x', s)
10576 >>> y = FP('y', s)
10577 >>> fpAdd(rm, x, y)
10578 x + y
10579 >>> fpAdd(RTZ(), x, y) # default rounding mode is RTZ
10580 fpAdd(RTZ(), x, y)
10581 >>> fpAdd(rm, x, y).sort()
10582 FPSort(8, 24)
10583 """
10584 return _mk_fp_bin(Z3_mk_fpa_add, rm, a, b, ctx)
10585
10586

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

10892def fpBVToFP(v, sort, ctx=None):
10893 """Create a Z3 floating-point conversion expression that represents the
10894 conversion from a bit-vector term to a floating-point term.
10895
10896 >>> x_bv = BitVecVal(0x3F800000, 32)
10897 >>> x_fp = fpBVToFP(x_bv, Float32())
10898 >>> x_fp
10899 fpToFP(1065353216)
10900 >>> simplify(x_fp)
10901 1
10902 """
10903 _z3_assert(is_bv(v), "First argument must be a Z3 bit-vector expression")
10904 _z3_assert(is_fp_sort(sort), "Second argument must be a Z3 floating-point sort.")
10905 ctx = _get_ctx(ctx)
10906 return FPRef(Z3_mk_fpa_to_fp_bv(ctx.ref(), v.ast, sort.ast), ctx)
10907
10908
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 10617 of file z3py.py.

10617def fpDiv(rm, a, b, ctx=None):
10618 """Create a Z3 floating-point division expression.
10619
10620 >>> s = FPSort(8, 24)
10621 >>> rm = RNE()
10622 >>> x = FP('x', s)
10623 >>> y = FP('y', s)
10624 >>> fpDiv(rm, x, y)
10625 x / y
10626 >>> fpDiv(rm, x, y).sort()
10627 FPSort(8, 24)
10628 """
10629 return _mk_fp_bin(Z3_mk_fpa_div, rm, a, b, ctx)
10630
10631

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

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

◆ fpFMA()

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

Definition at line 10676 of file z3py.py.

10676def fpFMA(rm, a, b, c, ctx=None):
10677 """Create a Z3 floating-point fused multiply-add expression.
10678 """
10679 return _mk_fp_tern(Z3_mk_fpa_fma, rm, a, b, c, ctx)
10680
10681

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

10824def fpFP(sgn, exp, sig, ctx=None):
10825 """Create the Z3 floating-point value `fpFP(sgn, sig, exp)` from the three bit-vectors sgn, sig, and exp.
10826
10827 >>> s = FPSort(8, 24)
10828 >>> x = fpFP(BitVecVal(1, 1), BitVecVal(2**7-1, 8), BitVecVal(2**22, 23))
10829 >>> print(x)
10830 fpFP(1, 127, 4194304)
10831 >>> xv = FPVal(-1.5, s)
10832 >>> print(xv)
10833 -1.5
10834 >>> slvr = Solver()
10835 >>> slvr.add(fpEQ(x, xv))
10836 >>> slvr.check()
10837 sat
10838 >>> xv = FPVal(+1.5, s)
10839 >>> print(xv)
10840 1.5
10841 >>> slvr = Solver()
10842 >>> slvr.add(fpEQ(x, xv))
10843 >>> slvr.check()
10844 unsat
10845 """
10846 _z3_assert(is_bv(sgn) and is_bv(exp) and is_bv(sig), "sort mismatch")
10847 _z3_assert(sgn.sort().size() == 1, "sort mismatch")
10848 ctx = _get_ctx(ctx)
10849 _z3_assert(ctx == sgn.ctx == exp.ctx == sig.ctx, "context mismatch")
10850 return FPRef(Z3_mk_fpa_fp(ctx.ref(), sgn.ast, exp.ast, sig.ast), ctx)
10851
10852
Z3_ast Z3_API Z3_mk_fpa_fp(Z3_context c, Z3_ast sgn, Z3_ast exp, Z3_ast sig)
Create an expression of FloatingPoint sort from three bit-vector expressions.

◆ fpFPToFP()

fpFPToFP ( rm,
v,
sort,
ctx = None )
Create a Z3 floating-point conversion expression that represents the
conversion from a floating-point term to a floating-point term of different precision.

>>> x_sgl = FPVal(1.0, Float32())
>>> x_dbl = fpFPToFP(RNE(), x_sgl, Float64())
>>> x_dbl
fpToFP(RNE(), 1)
>>> simplify(x_dbl)
1
>>> x_dbl.sort()
FPSort(11, 53)

Definition at line 10909 of file z3py.py.

10909def fpFPToFP(rm, v, sort, ctx=None):
10910 """Create a Z3 floating-point conversion expression that represents the
10911 conversion from a floating-point term to a floating-point term of different precision.
10912
10913 >>> x_sgl = FPVal(1.0, Float32())
10914 >>> x_dbl = fpFPToFP(RNE(), x_sgl, Float64())
10915 >>> x_dbl
10916 fpToFP(RNE(), 1)
10917 >>> simplify(x_dbl)
10918 1
10919 >>> x_dbl.sort()
10920 FPSort(11, 53)
10921 """
10922 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10923 _z3_assert(is_fp(v), "Second argument must be a Z3 floating-point expression.")
10924 _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
10925 ctx = _get_ctx(ctx)
10926 return FPRef(Z3_mk_fpa_to_fp_float(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
10927
10928
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 10788 of file z3py.py.

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

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

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

◆ fpInfinity()

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

Definition at line 10364 of file z3py.py.

10364def fpInfinity(s, negative):
10365 """Create a Z3 floating-point +oo or -oo term."""
10366 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10367 _z3_assert(isinstance(negative, bool), "expected Boolean flag")
10368 return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, negative), s.ctx)
10369
10370
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 10706 of file z3py.py.

10706def fpIsInf(a, ctx=None):
10707 """Create a Z3 floating-point isInfinite expression.
10708
10709 >>> s = FPSort(8, 24)
10710 >>> x = FP('x', s)
10711 >>> fpIsInf(x)
10712 fpIsInf(x)
10713 """
10714 return _mk_fp_unary_pred(Z3_mk_fpa_is_infinite, a, ctx)
10715
10716

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

10694def fpIsNaN(a, ctx=None):
10695 """Create a Z3 floating-point isNaN expression.
10696
10697 >>> s = FPSort(8, 24)
10698 >>> x = FP('x', s)
10699 >>> y = FP('y', s)
10700 >>> fpIsNaN(x)
10701 fpIsNaN(x)
10702 """
10703 return _mk_fp_unary_pred(Z3_mk_fpa_is_nan, a, ctx)
10704
10705

◆ fpIsNegative()

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

Definition at line 10735 of file z3py.py.

10735def fpIsNegative(a, ctx=None):
10736 """Create a Z3 floating-point isNegative expression.
10737 """
10738 return _mk_fp_unary_pred(Z3_mk_fpa_is_negative, a, ctx)
10739
10740

◆ fpIsNormal()

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

Definition at line 10723 of file z3py.py.

10723def fpIsNormal(a, ctx=None):
10724 """Create a Z3 floating-point isNormal expression.
10725 """
10726 return _mk_fp_unary_pred(Z3_mk_fpa_is_normal, a, ctx)
10727
10728

◆ fpIsPositive()

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

Definition at line 10741 of file z3py.py.

10741def fpIsPositive(a, ctx=None):
10742 """Create a Z3 floating-point isPositive expression.
10743 """
10744 return _mk_fp_unary_pred(Z3_mk_fpa_is_positive, a, ctx)
10745
10746

◆ fpIsSubnormal()

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

Definition at line 10729 of file z3py.py.

10729def fpIsSubnormal(a, ctx=None):
10730 """Create a Z3 floating-point isSubnormal expression.
10731 """
10732 return _mk_fp_unary_pred(Z3_mk_fpa_is_subnormal, a, ctx)
10733
10734

◆ fpIsZero()

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

Definition at line 10717 of file z3py.py.

10717def fpIsZero(a, ctx=None):
10718 """Create a Z3 floating-point isZero expression.
10719 """
10720 return _mk_fp_unary_pred(Z3_mk_fpa_is_zero, a, ctx)
10721
10722

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

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

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

10752def fpLT(a, b, ctx=None):
10753 """Create the Z3 floating-point expression `other < self`.
10754
10755 >>> x, y = FPs('x y', FPSort(8, 24))
10756 >>> fpLT(x, y)
10757 x < y
10758 >>> (x < y).sexpr()
10759 '(fp.lt x y)'
10760 """
10761 return _mk_fp_bin_pred(Z3_mk_fpa_lt, a, b, ctx)
10762
10763

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

10661def fpMax(a, b, ctx=None):
10662 """Create a Z3 floating-point maximum expression.
10663
10664 >>> s = FPSort(8, 24)
10665 >>> rm = RNE()
10666 >>> x = FP('x', s)
10667 >>> y = FP('y', s)
10668 >>> fpMax(x, y)
10669 fpMax(x, y)
10670 >>> fpMax(x, y).sort()
10671 FPSort(8, 24)
10672 """
10673 return _mk_fp_bin_norm(Z3_mk_fpa_max, a, b, ctx)
10674
10675

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

10646def fpMin(a, b, ctx=None):
10647 """Create a Z3 floating-point minimum expression.
10648
10649 >>> s = FPSort(8, 24)
10650 >>> rm = RNE()
10651 >>> x = FP('x', s)
10652 >>> y = FP('y', s)
10653 >>> fpMin(x, y)
10654 fpMin(x, y)
10655 >>> fpMin(x, y).sort()
10656 FPSort(8, 24)
10657 """
10658 return _mk_fp_bin_norm(Z3_mk_fpa_min, a, b, ctx)
10659
10660

◆ fpMinusInfinity()

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

Definition at line 10358 of file z3py.py.

10358def fpMinusInfinity(s):
10359 """Create a Z3 floating-point -oo term."""
10360 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10361 return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, True), s.ctx)
10362
10363

◆ fpMinusZero()

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

Definition at line 10377 of file z3py.py.

10377def fpMinusZero(s):
10378 """Create a Z3 floating-point -0.0 term."""
10379 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10380 return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, True), s.ctx)
10381
10382
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 10602 of file z3py.py.

10602def fpMul(rm, a, b, ctx=None):
10603 """Create a Z3 floating-point multiplication expression.
10604
10605 >>> s = FPSort(8, 24)
10606 >>> rm = RNE()
10607 >>> x = FP('x', s)
10608 >>> y = FP('y', s)
10609 >>> fpMul(rm, x, y)
10610 x * y
10611 >>> fpMul(rm, x, y).sort()
10612 FPSort(8, 24)
10613 """
10614 return _mk_fp_bin(Z3_mk_fpa_mul, rm, a, b, ctx)
10615
10616

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

10324def fpNaN(s):
10325 """Create a Z3 floating-point NaN term.
10326
10327 >>> s = FPSort(8, 24)
10328 >>> set_fpa_pretty(True)
10329 >>> fpNaN(s)
10330 NaN
10331 >>> pb = get_fpa_pretty()
10332 >>> set_fpa_pretty(False)
10333 >>> fpNaN(s)
10334 fpNaN(FPSort(8, 24))
10335 >>> set_fpa_pretty(pb)
10336 """
10337 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10338 return FPNumRef(Z3_mk_fpa_nan(s.ctx_ref(), s.ast), s.ctx)
10339
10340
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 10502 of file z3py.py.

10502def fpNeg(a, ctx=None):
10503 """Create a Z3 floating-point addition expression.
10504
10505 >>> s = FPSort(8, 24)
10506 >>> rm = RNE()
10507 >>> x = FP('x', s)
10508 >>> fpNeg(x)
10509 -x
10510 >>> fpNeg(x).sort()
10511 FPSort(8, 24)
10512 """
10513 ctx = _get_ctx(ctx)
10514 [a] = _coerce_fp_expr_list([a], ctx)
10515 return FPRef(Z3_mk_fpa_neg(ctx.ref(), a.as_ast()), ctx)
10516
10517
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 10812 of file z3py.py.

10812def fpNEQ(a, b, ctx=None):
10813 """Create the Z3 floating-point expression `Not(fpEQ(other, self))`.
10814
10815 >>> x, y = FPs('x y', FPSort(8, 24))
10816 >>> fpNEQ(x, y)
10817 Not(fpEQ(x, y))
10818 >>> (x != y).sexpr()
10819 '(distinct x y)'
10820 """
10821 return Not(fpEQ(a, b, ctx))
10822
10823

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

10341def fpPlusInfinity(s):
10342 """Create a Z3 floating-point +oo term.
10343
10344 >>> s = FPSort(8, 24)
10345 >>> pb = get_fpa_pretty()
10346 >>> set_fpa_pretty(True)
10347 >>> fpPlusInfinity(s)
10348 +oo
10349 >>> set_fpa_pretty(False)
10350 >>> fpPlusInfinity(s)
10351 fpPlusInfinity(FPSort(8, 24))
10352 >>> set_fpa_pretty(pb)
10353 """
10354 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10355 return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, False), s.ctx)
10356
10357

◆ fpPlusZero()

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

Definition at line 10371 of file z3py.py.

10371def fpPlusZero(s):
10372 """Create a Z3 floating-point +0.0 term."""
10373 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10374 return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, False), s.ctx)
10375
10376

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

10929def fpRealToFP(rm, v, sort, ctx=None):
10930 """Create a Z3 floating-point conversion expression that represents the
10931 conversion from a real term to a floating-point term.
10932
10933 >>> x_r = RealVal(1.5)
10934 >>> x_fp = fpRealToFP(RNE(), x_r, Float32())
10935 >>> x_fp
10936 fpToFP(RNE(), 3/2)
10937 >>> simplify(x_fp)
10938 1.5
10939 """
10940 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10941 _z3_assert(is_real(v), "Second argument must be a Z3 expression or real sort.")
10942 _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
10943 ctx = _get_ctx(ctx)
10944 return FPRef(Z3_mk_fpa_to_fp_real(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
10945
10946
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 10632 of file z3py.py.

10632def fpRem(a, b, ctx=None):
10633 """Create a Z3 floating-point remainder expression.
10634
10635 >>> s = FPSort(8, 24)
10636 >>> x = FP('x', s)
10637 >>> y = FP('y', s)
10638 >>> fpRem(x, y)
10639 fpRem(x, y)
10640 >>> fpRem(x, y).sort()
10641 FPSort(8, 24)
10642 """
10643 return _mk_fp_bin_norm(Z3_mk_fpa_rem, a, b, ctx)
10644
10645

◆ fpRoundToIntegral()

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

Definition at line 10688 of file z3py.py.

10688def fpRoundToIntegral(rm, a, ctx=None):
10689 """Create a Z3 floating-point roundToIntegral expression.
10690 """
10691 return _mk_fp_unary(Z3_mk_fpa_round_to_integral, rm, a, ctx)
10692
10693

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

10460def FPs(names, fpsort, ctx=None):
10461 """Return an array of floating-point constants.
10462
10463 >>> x, y, z = FPs('x y z', FPSort(8, 24))
10464 >>> x.sort()
10465 FPSort(8, 24)
10466 >>> x.sbits()
10467 24
10468 >>> x.ebits()
10469 8
10470 >>> fpMul(RNE(), fpAdd(RNE(), x, y), z)
10471 (x + y) * z
10472 """
10473 ctx = _get_ctx(ctx)
10474 if isinstance(names, str):
10475 names = names.split(" ")
10476 return [FP(name, fpsort, ctx) for name in names]
10477
10478

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

10947def fpSignedToFP(rm, v, sort, ctx=None):
10948 """Create a Z3 floating-point conversion expression that represents the
10949 conversion from a signed bit-vector term (encoding an integer) to a floating-point term.
10950
10951 >>> x_signed = BitVecVal(-5, BitVecSort(32))
10952 >>> x_fp = fpSignedToFP(RNE(), x_signed, Float32())
10953 >>> x_fp
10954 fpToFP(RNE(), 4294967291)
10955 >>> simplify(x_fp)
10956 -1.25*(2**2)
10957 """
10958 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10959 _z3_assert(is_bv(v), "Second argument must be a Z3 bit-vector expression")
10960 _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
10961 ctx = _get_ctx(ctx)
10962 return FPRef(Z3_mk_fpa_to_fp_signed(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
10963
10964
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 10265 of file z3py.py.

10265def FPSort(ebits, sbits, ctx=None):
10266 """Return a Z3 floating-point sort of the given sizes. If `ctx=None`, then the global context is used.
10267
10268 >>> Single = FPSort(8, 24)
10269 >>> Double = FPSort(11, 53)
10270 >>> Single
10271 FPSort(8, 24)
10272 >>> x = Const('x', Single)
10273 >>> eq(x, FP('x', FPSort(8, 24)))
10274 True
10275 """
10276 ctx = _get_ctx(ctx)
10277 return FPSortRef(Z3_mk_fpa_sort(ctx.ref(), ebits, sbits), ctx)
10278
10279
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 10682 of file z3py.py.

10682def fpSqrt(rm, a, ctx=None):
10683 """Create a Z3 floating-point square root expression.
10684 """
10685 return _mk_fp_unary(Z3_mk_fpa_sqrt, rm, a, ctx)
10686
10687

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

10587def fpSub(rm, a, b, ctx=None):
10588 """Create a Z3 floating-point subtraction expression.
10589
10590 >>> s = FPSort(8, 24)
10591 >>> rm = RNE()
10592 >>> x = FP('x', s)
10593 >>> y = FP('y', s)
10594 >>> fpSub(rm, x, y)
10595 x - y
10596 >>> fpSub(rm, x, y).sort()
10597 FPSort(8, 24)
10598 """
10599 return _mk_fp_bin(Z3_mk_fpa_sub, rm, a, b, ctx)
10600
10601

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

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

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

10983def fpToFPUnsigned(rm, x, s, ctx=None):
10984 """Create a Z3 floating-point conversion expression, from unsigned bit-vector to floating-point expression."""
10985 if z3_debug():
10986 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
10987 _z3_assert(is_bv(x), "Second argument must be a Z3 bit-vector expression")
10988 _z3_assert(is_fp_sort(s), "Third argument must be Z3 floating-point sort")
10989 ctx = _get_ctx(ctx)
10990 return FPRef(Z3_mk_fpa_to_fp_unsigned(ctx.ref(), rm.ast, x.ast, s.ast), ctx)
10991
10992
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 11057 of file z3py.py.

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

11037def fpToReal(x, ctx=None):
11038 """Create a Z3 floating-point conversion expression, from floating-point expression to real.
11039
11040 >>> x = FP('x', FPSort(8, 24))
11041 >>> y = fpToReal(x)
11042 >>> print(is_fp(x))
11043 True
11044 >>> print(is_real(y))
11045 True
11046 >>> print(is_fp(y))
11047 False
11048 >>> print(is_real(x))
11049 False
11050 """
11051 if z3_debug():
11052 _z3_assert(is_fp(x), "First argument must be a Z3 floating-point expression")
11053 ctx = _get_ctx(ctx)
11054 return ArithRef(Z3_mk_fpa_to_real(ctx.ref(), x.ast), ctx)
11055
11056
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 10993 of file z3py.py.

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

11015def fpToUBV(rm, x, s, ctx=None):
11016 """Create a Z3 floating-point conversion expression, from floating-point expression to unsigned bit-vector.
11017
11018 >>> x = FP('x', FPSort(8, 24))
11019 >>> y = fpToUBV(RTZ(), x, BitVecSort(32))
11020 >>> print(is_fp(x))
11021 True
11022 >>> print(is_bv(y))
11023 True
11024 >>> print(is_fp(y))
11025 False
11026 >>> print(is_bv(x))
11027 False
11028 """
11029 if z3_debug():
11030 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression")
11031 _z3_assert(is_fp(x), "Second argument must be a Z3 floating-point expression")
11032 _z3_assert(is_bv_sort(s), "Third argument must be Z3 bit-vector sort")
11033 ctx = _get_ctx(ctx)
11034 return BitVecRef(Z3_mk_fpa_to_ubv(ctx.ref(), rm.ast, x.ast, s.size()), ctx)
11035
11036
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 10965 of file z3py.py.

10965def fpUnsignedToFP(rm, v, sort, ctx=None):
10966 """Create a Z3 floating-point conversion expression that represents the
10967 conversion from an unsigned bit-vector term (encoding an integer) to a floating-point term.
10968
10969 >>> x_signed = BitVecVal(-5, BitVecSort(32))
10970 >>> x_fp = fpUnsignedToFP(RNE(), x_signed, Float32())
10971 >>> x_fp
10972 fpToFPUnsigned(RNE(), 4294967291)
10973 >>> simplify(x_fp)
10974 1*(2**32)
10975 """
10976 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10977 _z3_assert(is_bv(v), "Second argument must be a Z3 bit-vector expression")
10978 _z3_assert(is_fp_sort(sort), "Third argument must be a Z3 floating-point sort.")
10979 ctx = _get_ctx(ctx)
10980 return FPRef(Z3_mk_fpa_to_fp_unsigned(ctx.ref(), rm.ast, v.ast, sort.ast), ctx)
10981
10982

◆ FPVal()

FPVal ( sig,
exp = None,
fps = None,
ctx = None )
Return a floating-point value of value `val` and sort `fps`.
If `ctx=None`, then the global context is used.

>>> v = FPVal(20.0, FPSort(8, 24))
>>> v
1.25*(2**4)
>>> print("0x%.8x" % v.exponent_as_long(False))
0x00000004
>>> v = FPVal(2.25, FPSort(8, 24))
>>> v
1.125*(2**1)
>>> v = FPVal(-2.25, FPSort(8, 24))
>>> v
-1.125*(2**1)
>>> FPVal(-0.0, FPSort(8, 24))
-0.0
>>> FPVal(0.0, FPSort(8, 24))
+0.0
>>> FPVal(+0.0, FPSort(8, 24))
+0.0

Definition at line 10390 of file z3py.py.

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

◆ fpZero()

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

Definition at line 10383 of file z3py.py.

10383def fpZero(s, negative):
10384 """Create a Z3 floating-point +0.0 or -0.0 term."""
10385 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
10386 _z3_assert(isinstance(negative, bool), "expected Boolean flag")
10387 return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, negative), s.ctx)
10388
10389

◆ FreshBool()

FreshBool ( prefix = "b",
ctx = None )
Return a fresh Boolean constant in the given context using the given prefix.

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

>>> b1 = FreshBool()
>>> b2 = FreshBool()
>>> eq(b1, b2)
False

Definition at line 1904 of file z3py.py.

1904def FreshBool(prefix="b", ctx=None):
1905 """Return a fresh Boolean constant in the given context using the given prefix.
1906
1907 If `ctx=None`, then the global context is used.
1908
1909 >>> b1 = FreshBool()
1910 >>> b2 = FreshBool()
1911 >>> eq(b1, b2)
1912 False
1913 """
1914 ctx = _get_ctx(ctx)
1915 return BoolRef(Z3_mk_fresh_const(ctx.ref(), prefix, BoolSort(ctx).ast), ctx)
1916
1917
Z3_ast Z3_API Z3_mk_fresh_const(Z3_context c, Z3_string prefix, Z3_sort ty)
Declare and create a fresh constant.

◆ FreshConst()

FreshConst ( sort,
prefix = "c" )
Create a fresh constant of a specified sort

Definition at line 1567 of file z3py.py.

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

◆ FreshFunction()

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

Definition at line 943 of file z3py.py.

943def FreshFunction(*sig):
944 """Create a new fresh Z3 uninterpreted function with the given sorts.
945 """
946 sig = _get_args(sig)
947 if z3_debug():
948 _z3_assert(len(sig) > 0, "At least two arguments expected")
949 arity = len(sig) - 1
950 rng = sig[arity]
951 if z3_debug():
952 _z3_assert(is_sort(rng), "Z3 sort expected")
953 dom = (z3.Sort * arity)()
954 for i in range(arity):
955 if z3_debug():
956 _z3_assert(is_sort(sig[i]), "Z3 sort expected")
957 dom[i] = sig[i].ast
958 ctx = rng.ctx
959 return FuncDeclRef(Z3_mk_fresh_func_decl(ctx.ref(), "f", arity, dom, rng.ast), ctx)
960
961
Z3_func_decl Z3_API Z3_mk_fresh_func_decl(Z3_context c, Z3_string prefix, unsigned domain_size, Z3_sort const domain[], Z3_sort range)
Declare a fresh constant or function.

◆ FreshInt()

FreshInt ( prefix = "x",
ctx = None )
Return a fresh integer constant in the given context using the given prefix.

>>> x = FreshInt()
>>> y = FreshInt()
>>> eq(x, y)
False
>>> x.sort()
Int

Definition at line 3432 of file z3py.py.

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

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

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

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

11360def Full(s):
11361 """Create the regular expression that accepts the universal language
11362 >>> e = Full(ReSort(SeqSort(IntSort())))
11363 >>> print(e)
11364 Full(ReSort(Seq(Int)))
11365 >>> e1 = Full(ReSort(StringSort()))
11366 >>> print(e1)
11367 Full(ReSort(String))
11368 """
11369 if isinstance(s, ReSortRef):
11370 return ReRef(Z3_mk_re_full(s.ctx_ref(), s.ast), s.ctx)
11371 raise Z3Exception("Non-sequence, non-regular expression sort passed to Full")
11372
11373
11374
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 5099 of file z3py.py.

5099def FullSet(s):
5100 """Create the full set
5101 >>> FullSet(IntSort())
5102 K(Int, True)
5103 """
5104 ctx = s.ctx
5105 return ArrayRef(Z3_mk_full_set(ctx.ref(), s.ast), ctx)
5106
5107
Z3_ast Z3_API Z3_mk_full_set(Z3_context c, Z3_sort domain)
Create the full set.

◆ Function()

Function ( name,
* sig )
Create a new Z3 uninterpreted function with the given sorts.

>>> f = Function('f', IntSort(), IntSort())
>>> f(f(0))
f(f(0))

Definition at line 920 of file z3py.py.

920def Function(name, *sig):
921 """Create a new Z3 uninterpreted function with the given sorts.
922
923 >>> f = Function('f', IntSort(), IntSort())
924 >>> f(f(0))
925 f(f(0))
926 """
927 sig = _get_args(sig)
928 if z3_debug():
929 _z3_assert(len(sig) > 0, "At least two arguments expected")
930 arity = len(sig) - 1
931 rng = sig[arity]
932 if z3_debug():
933 _z3_assert(is_sort(rng), "Z3 sort expected")
934 dom = (Sort * arity)()
935 for i in range(arity):
936 if z3_debug():
937 _z3_assert(is_sort(sig[i]), "Z3 sort expected")
938 dom[i] = sig[i].ast
939 ctx = rng.ctx
940 return FuncDeclRef(Z3_mk_func_decl(ctx.ref(), to_symbol(name, ctx), arity, dom, rng.ast), ctx)
941
942
Z3_func_decl Z3_API Z3_mk_func_decl(Z3_context c, Z3_symbol s, unsigned domain_size, Z3_sort const domain[], Z3_sort range)
Declare a constant or function.

◆ get_as_array_func()

get_as_array_func ( n)
Return the function declaration f associated with a Z3 expression of the form (_ as-array f).

Definition at line 6940 of file z3py.py.

6940def get_as_array_func(n):
6941 """Return the function declaration f associated with a Z3 expression of the form (_ as-array f)."""
6942 if z3_debug():
6943 _z3_assert(is_as_array(n), "as-array Z3 expression expected.")
6944 return FuncDeclRef(Z3_get_as_array_func_decl(n.ctx.ref(), n.as_ast()), n.ctx)
6945
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 9677 of file z3py.py.

9677def get_default_fp_sort(ctx=None):
9678 return FPSort(_dflt_fpsort_ebits, _dflt_fpsort_sbits, ctx)
9679
9680

◆ get_default_rounding_mode()

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

Definition at line 9644 of file z3py.py.

9644def get_default_rounding_mode(ctx=None):
9645 """Retrieves the global default rounding mode."""
9646 global _dflt_rounding_mode
9647 if _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO:
9648 return RTZ(ctx)
9649 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE:
9650 return RTN(ctx)
9651 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE:
9652 return RTP(ctx)
9653 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN:
9654 return RNE(ctx)
9655 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY:
9656 return RNA(ctx)
9657
9658

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

4851def get_map_func(a):
4852 """Return the function declaration associated with a Z3 map array expression.
4853
4854 >>> f = Function('f', IntSort(), IntSort())
4855 >>> b = Array('b', IntSort(), IntSort())
4856 >>> a = Map(f, b)
4857 >>> eq(f, get_map_func(a))
4858 True
4859 >>> get_map_func(a)
4860 f
4861 >>> get_map_func(a)(0)
4862 f(0)
4863 """
4864 if z3_debug():
4865 _z3_assert(is_map(a), "Z3 array map expression expected.")
4866 return FuncDeclRef(
4868 a.ctx_ref(),
4869 Z3_get_decl_ast_parameter(a.ctx_ref(), a.decl().ast, 0),
4870 ),
4871 ctx=a.ctx,
4872 )
4873
4874
Z3_func_decl Z3_API Z3_to_func_decl(Z3_context c, Z3_ast a)
Convert an AST into a FUNC_DECL_AST. This is just type casting.
Z3_ast Z3_API Z3_get_decl_ast_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the expression value associated with an expression parameter.

◆ get_param()

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

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

Definition at line 334 of file z3py.py.

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

◆ get_var_index()

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

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

Definition at line 1438 of file z3py.py.

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

◆ get_version()

get_version ( )

Definition at line 100 of file z3py.py.

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

◆ get_version_string()

get_version_string ( )

Definition at line 91 of file z3py.py.

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

◆ help_simplify()

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

Definition at line 9150 of file z3py.py.

9150def help_simplify():
9151 """Return a string describing all options available for Z3 `simplify` procedure."""
9152 print(Z3_simplify_get_help(main_ctx().ref()))
9153
9154
Z3_string Z3_API Z3_simplify_get_help(Z3_context c)
Return a string describing all available parameters.

◆ If()

If ( a,
b,
c,
ctx = None )
Create a Z3 if-then-else expression.

>>> x = Int('x')
>>> y = Int('y')
>>> max = If(x > y, x, y)
>>> max
If(x > y, x, y)
>>> simplify(max)
If(x <= y, y, x)

Definition at line 1484 of file z3py.py.

1484def If(a, b, c, ctx=None):
1485 """Create a Z3 if-then-else expression.
1486
1487 >>> x = Int('x')
1488 >>> y = Int('y')
1489 >>> max = If(x > y, x, y)
1490 >>> max
1491 If(x > y, x, y)
1492 >>> simplify(max)
1493 If(x <= y, y, x)
1494 """
1495 if isinstance(a, Probe) or isinstance(b, Tactic) or isinstance(c, Tactic):
1496 return Cond(a, b, c, ctx)
1497 else:
1498 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b, c], ctx))
1499 s = BoolSort(ctx)
1500 a = s.cast(a)
1501 b, c = _coerce_exprs(b, c, ctx)
1502 if z3_debug():
1503 _z3_assert(a.ctx == b.ctx, "Context mismatch")
1504 return _to_expr_ref(Z3_mk_ite(ctx.ref(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
1505
1506
Z3_ast Z3_API Z3_mk_ite(Z3_context c, Z3_ast t1, Z3_ast t2, Z3_ast t3)
Create an AST node representing an if-then-else: ite(t1, t2, t3).

Referenced by BoolRef.__add__(), ArithRef.__mul__(), BoolRef.__mul__(), and ToReal().

◆ Implies()

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

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

Definition at line 1918 of file z3py.py.

1918def Implies(a, b, ctx=None):
1919 """Create a Z3 implies expression.
1920
1921 >>> p, q = Bools('p q')
1922 >>> Implies(p, q)
1923 Implies(p, q)
1924 """
1925 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1926 s = BoolSort(ctx)
1927 a = s.cast(a)
1928 b = s.cast(b)
1929 return BoolRef(Z3_mk_implies(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
1930
1931
Z3_ast Z3_API Z3_mk_implies(Z3_context c, Z3_ast t1, Z3_ast t2)
Create an AST node representing t1 implies t2.

◆ IndexOf()

IndexOf ( s,
substr,
offset = None )
Retrieve the index of substring within a string starting at a specified offset.
>>> simplify(IndexOf("abcabc", "bc", 0))
1
>>> simplify(IndexOf("abcabc", "bc", 2))
4

Definition at line 11444 of file z3py.py.

11444def IndexOf(s, substr, offset=None):
11445 """Retrieve the index of substring within a string starting at a specified offset.
11446 >>> simplify(IndexOf("abcabc", "bc", 0))
11447 1
11448 >>> simplify(IndexOf("abcabc", "bc", 2))
11449 4
11450 """
11451 if offset is None:
11452 offset = IntVal(0)
11453 ctx = None
11454 if is_expr(offset):
11455 ctx = offset.ctx
11456 ctx = _get_ctx2(s, substr, ctx)
11457 s = _coerce_seq(s, ctx)
11458 substr = _coerce_seq(substr, ctx)
11459 if _is_int(offset):
11460 offset = IntVal(offset, ctx)
11461 return ArithRef(Z3_mk_seq_index(s.ctx_ref(), s.as_ast(), substr.as_ast(), offset.as_ast()), s.ctx)
11462
11463
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 11583 of file z3py.py.

11583def InRe(s, re):
11584 """Create regular expression membership test
11585 >>> re = Union(Re("a"),Re("b"))
11586 >>> print (simplify(InRe("a", re)))
11587 True
11588 >>> print (simplify(InRe("b", re)))
11589 True
11590 >>> print (simplify(InRe("c", re)))
11591 False
11592 """
11593 s = _coerce_seq(s, re.ctx)
11594 return BoolRef(Z3_mk_seq_in_re(s.ctx_ref(), s.as_ast(), re.as_ast()), s.ctx)
11595
11596
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 3393 of file z3py.py.

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

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

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

11617def Intersect(*args):
11618 """Create intersection of regular expressions.
11619 >>> re = Intersect(Re("a"), Re("b"), Re("c"))
11620 """
11621 args = _get_args(args)
11622 sz = len(args)
11623 if z3_debug():
11624 _z3_assert(sz > 0, "At least one argument expected.")
11625 _z3_assert(all([is_re(a) for a in args]), "All arguments must be regular expressions.")
11626 if sz == 1:
11627 return args[0]
11628 ctx = args[0].ctx
11629 v = (Ast * sz)()
11630 for i in range(sz):
11631 v[i] = args[i].as_ast()
11632 return ReRef(Z3_mk_re_intersect(ctx.ref(), sz, v), ctx)
11633
11634
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 3406 of file z3py.py.

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

◆ IntSort()

IntSort ( ctx = None)
Return the integer sort in the given context. If `ctx=None`, then the global context is used.

>>> IntSort()
Int
>>> x = Const('x', IntSort())
>>> is_int(x)
True
>>> x.sort() == IntSort()
True
>>> x.sort() == BoolSort()
False

Definition at line 3287 of file z3py.py.

3287def IntSort(ctx=None):
3288 """Return the integer sort in the given context. If `ctx=None`, then the global context is used.
3289
3290 >>> IntSort()
3291 Int
3292 >>> x = Const('x', IntSort())
3293 >>> is_int(x)
3294 True
3295 >>> x.sort() == IntSort()
3296 True
3297 >>> x.sort() == BoolSort()
3298 False
3299 """
3300 ctx = _get_ctx(ctx)
3301 return ArithSortRef(Z3_mk_int_sort(ctx.ref()), ctx)
3302
3303
Z3_sort Z3_API Z3_mk_int_sort(Z3_context c)
Create the integer type.

Referenced by FreshInt(), Int(), and IntVal().

◆ IntToStr()

IntToStr ( s)
Convert integer expression to string

Definition at line 11525 of file z3py.py.

11525def IntToStr(s):
11526 """Convert integer expression to string"""
11527 if not is_expr(s):
11528 s = _py2expr(s)
11529 return SeqRef(Z3_mk_int_to_str(s.ctx_ref(), s.as_ast()), s.ctx)
11530
11531
Z3_ast Z3_API Z3_mk_int_to_str(Z3_context c, Z3_ast s)
Integer to string conversion.

◆ IntVal()

IntVal ( val,
ctx = None )
Return a Z3 integer value. If `ctx=None`, then the global context is used.

>>> IntVal(1)
1
>>> IntVal("100")
100

Definition at line 3333 of file z3py.py.

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

Referenced by BoolRef.__mul__(), and _py2expr().

◆ IntVector()

IntVector ( prefix,
sz,
ctx = None )
Return a list of integer constants of size `sz`.

>>> X = IntVector('x', 3)
>>> X
[x__0, x__1, x__2]
>>> Sum(X)
x__0 + x__1 + x__2

Definition at line 3419 of file z3py.py.

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

◆ is_add()

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

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

Definition at line 2935 of file z3py.py.

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

◆ is_algebraic_value()

is_algebraic_value ( a)
Return `True` if `a` is an algebraic value of sort Real.

>>> is_algebraic_value(RealVal("3/5"))
False
>>> n = simplify(Sqrt(2))
>>> n
1.4142135623?
>>> is_algebraic_value(n)
True

Definition at line 2921 of file z3py.py.

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

◆ is_and()

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

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

Definition at line 1754 of file z3py.py.

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

◆ is_app()

is_app ( a)
Return `True` if `a` is a Z3 function application.

Note that, constants are function applications with 0 arguments.

>>> a = Int('a')
>>> is_app(a)
True
>>> is_app(a + 1)
True
>>> is_app(IntSort())
False
>>> is_app(1)
False
>>> is_app(IntVal(1))
True
>>> x = Int('x')
>>> is_app(ForAll(x, x >= 0))
False

Definition at line 1368 of file z3py.py.

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

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

◆ is_app_of()

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

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

Definition at line 1471 of file z3py.py.

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

Referenced by is_add(), is_and(), is_const_array(), is_default(), is_distinct(), is_div(), is_eq(), is_false(), is_ge(), is_gt(), is_idiv(), is_implies(), is_is_int(), is_K(), is_le(), is_lt(), is_map(), is_mod(), is_mul(), is_not(), is_or(), is_select(), is_store(), is_sub(), is_to_int(), is_to_real(), and is_true().

◆ is_arith()

is_arith ( a)
Return `True` if `a` is an arithmetical expression.

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

Definition at line 2808 of file z3py.py.

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

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

◆ is_arith_sort()

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

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

Definition at line 2507 of file z3py.py.

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

Referenced by ArithSortRef.subsort().

◆ is_array()

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

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

Definition at line 4786 of file z3py.py.

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

Referenced by Ext(), and Map().

◆ is_array_sort()

is_array_sort ( a)

Definition at line 4782 of file z3py.py.

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

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

6935def is_as_array(n):
6936 """Return true if n is a Z3 expression of the form (_ as-array f)."""
6937 return isinstance(n, ExprRef) and Z3_is_as_array(n.ctx.ref(), n.as_ast())
6938
6939
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 1704 of file z3py.py.

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

Referenced by _mk_quantifier().

◆ is_bv()

is_bv ( a)
Return `True` if `a` is a Z3 bit-vector expression.

>>> b = BitVec('b', 32)
>>> is_bv(b)
True
>>> is_bv(b + 10)
True
>>> is_bv(Int('x'))
False

Definition at line 4096 of file z3py.py.

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

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

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

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

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

◆ is_const()

is_const ( a)
Return `True` if `a` is Z3 constant/variable expression.

>>> a = Int('a')
>>> is_const(a)
True
>>> is_const(a + 1)
False
>>> is_const(1)
False
>>> is_const(IntVal(1))
True
>>> x = Int('x')
>>> is_const(ForAll(x, x >= 0))
False

Definition at line 1394 of file z3py.py.

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

Referenced by ModelRef.__getitem__(), _mk_quantifier(), Solver.assert_and_track(), and ModelRef.get_interp().

◆ is_const_array()

is_const_array ( a)
Return `True` if `a` is a Z3 constant array.

>>> a = K(IntSort(), 10)
>>> is_const_array(a)
True
>>> a = Array('a', IntSort(), IntSort())
>>> is_const_array(a)
False

Definition at line 4800 of file z3py.py.

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

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

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

◆ is_distinct()

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

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

Definition at line 1812 of file z3py.py.

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

◆ is_div()

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

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

Definition at line 2971 of file z3py.py.

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

◆ is_eq()

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

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

Definition at line 1802 of file z3py.py.

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

Referenced by AstRef.__bool__().

◆ is_expr()

is_expr ( a)
Return `True` if `a` is a Z3 expression.

>>> a = Int('a')
>>> is_expr(a)
True
>>> is_expr(a + 1)
True
>>> is_expr(IntSort())
False
>>> is_expr(1)
False
>>> is_expr(IntVal(1))
True
>>> x = Int('x')
>>> is_expr(ForAll(x, x >= 0))
True
>>> is_expr(FPVal(1.0))
True

Definition at line 1345 of file z3py.py.

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

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

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

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

◆ is_finite_domain()

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

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

Definition at line 8028 of file z3py.py.

8028def is_finite_domain(a):
8029 """Return `True` if `a` is a Z3 finite-domain expression.
8030
8031 >>> s = FiniteDomainSort('S', 100)
8032 >>> b = Const('b', s)
8033 >>> is_finite_domain(b)
8034 True
8035 >>> is_finite_domain(Int('x'))
8036 False
8037 """
8038 return isinstance(a, FiniteDomainRef)
8039
8040

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

8005def is_finite_domain_sort(s):
8006 """Return True if `s` is a Z3 finite-domain sort.
8007
8008 >>> is_finite_domain_sort(FiniteDomainSort('S', 100))
8009 True
8010 >>> is_finite_domain_sort(IntSort())
8011 False
8012 """
8013 return isinstance(s, FiniteDomainSortRef)
8014
8015

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

8082def is_finite_domain_value(a):
8083 """Return `True` if `a` is a Z3 finite-domain value.
8084
8085 >>> s = FiniteDomainSort('S', 100)
8086 >>> b = Const('b', s)
8087 >>> is_finite_domain_value(b)
8088 False
8089 >>> b = FiniteDomainVal(10, s)
8090 >>> b
8091 10
8092 >>> is_finite_domain_value(b)
8093 True
8094 """
8095 return is_finite_domain(a) and _is_numeral(a.ctx, a.as_ast())
8096
8097

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

10236def is_fp(a):
10237 """Return `True` if `a` is a Z3 floating-point expression.
10238
10239 >>> b = FP('b', FPSort(8, 24))
10240 >>> is_fp(b)
10241 True
10242 >>> is_fp(b + 1.0)
10243 True
10244 >>> is_fp(Int('x'))
10245 False
10246 """
10247 return isinstance(a, FPRef)
10248
10249

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

9810def is_fp_sort(s):
9811 """Return True if `s` is a Z3 floating-point sort.
9812
9813 >>> is_fp_sort(FPSort(8, 24))
9814 True
9815 >>> is_fp_sort(IntSort())
9816 False
9817 """
9818 return isinstance(s, FPSortRef)
9819
9820

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

10250def is_fp_value(a):
10251 """Return `True` if `a` is a Z3 floating-point numeral value.
10252
10253 >>> b = FP('b', FPSort(8, 24))
10254 >>> is_fp_value(b)
10255 False
10256 >>> b = FPVal(1.0, FPSort(8, 24))
10257 >>> b
10258 1
10259 >>> is_fp_value(b)
10260 True
10261 """
10262 return is_fp(a) and _is_numeral(a.ctx, a.ast)
10263
10264

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

10070def is_fprm(a):
10071 """Return `True` if `a` is a Z3 floating-point rounding mode expression.
10072
10073 >>> rm = RNE()
10074 >>> is_fprm(rm)
10075 True
10076 >>> rm = 1.0
10077 >>> is_fprm(rm)
10078 False
10079 """
10080 return isinstance(a, FPRMRef)
10081
10082

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

9821def is_fprm_sort(s):
9822 """Return True if `s` is a Z3 floating-point rounding mode sort.
9823
9824 >>> is_fprm_sort(FPSort(8, 24))
9825 False
9826 >>> is_fprm_sort(RNE().sort())
9827 True
9828 """
9829 return isinstance(s, FPRMSortRef)
9830
9831# FP Expressions
9832
9833

◆ is_fprm_value()

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

Definition at line 10083 of file z3py.py.

10083def is_fprm_value(a):
10084 """Return `True` if `a` is a Z3 floating-point rounding mode numeral value."""
10085 return is_fprm(a) and _is_numeral(a.ctx, a.ast)
10086
10087# FP Numerals
10088
10089

◆ is_func_decl()

is_func_decl ( a)
Return `True` if `a` is a Z3 function declaration.

>>> f = Function('f', IntSort(), IntSort())
>>> is_func_decl(f)
True
>>> x = Real('x')
>>> is_func_decl(x)
False

Definition at line 907 of file z3py.py.

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

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

◆ is_ge()

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

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

Definition at line 3036 of file z3py.py.

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

◆ is_gt()

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

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

Definition at line 3048 of file z3py.py.

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

◆ is_idiv()

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

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

Definition at line 2988 of file z3py.py.

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

◆ is_implies()

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

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

Definition at line 1778 of file z3py.py.

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

◆ is_int()

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

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

Definition at line 2829 of file z3py.py.

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

◆ is_int_value()

is_int_value ( a)
Return `True` if `a` is an integer value of sort Int.

>>> is_int_value(IntVal(1))
True
>>> is_int_value(1)
False
>>> is_int_value(Int('x'))
False
>>> n = Int('x') + 1
>>> n
x + 1
>>> n.arg(1)
1
>>> is_int_value(n.arg(1))
True
>>> is_int_value(RealVal("1/3"))
False
>>> is_int_value(RealVal(1))
False

Definition at line 2875 of file z3py.py.

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

◆ is_is_int()

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

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

Definition at line 3060 of file z3py.py.

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

◆ is_K()

is_K ( a)
Return `True` if `a` is a Z3 constant array.

>>> a = K(IntSort(), 10)
>>> is_K(a)
True
>>> a = Array('a', IntSort(), IntSort())
>>> is_K(a)
False

Definition at line 4813 of file z3py.py.

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

◆ is_le()

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

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

Definition at line 3012 of file z3py.py.

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

◆ is_lt()

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

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

Definition at line 3024 of file z3py.py.

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

◆ is_map()

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

>>> f = Function('f', IntSort(), IntSort())
>>> b = Array('b', IntSort(), IntSort())
>>> a  = Map(f, b)
>>> a
Map(f, b)
>>> is_map(a)
True
>>> is_map(b)
False

Definition at line 4826 of file z3py.py.

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

Referenced by get_map_func().

◆ is_mod()

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

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

Definition at line 3000 of file z3py.py.

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

◆ is_mul()

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

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

Definition at line 2947 of file z3py.py.

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

◆ is_not()

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

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

Definition at line 1790 of file z3py.py.

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

Referenced by mk_not().

◆ is_or()

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

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

Definition at line 1766 of file z3py.py.

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

◆ is_pattern()

is_pattern ( a)
Return `True` if `a` is a Z3 pattern (hint for quantifier instantiation.

>>> f = Function('f', IntSort(), IntSort())
>>> x = Int('x')
>>> q = ForAll(x, f(x) == 0, patterns = [ f(x) ])
>>> q
ForAll(x, f(x) == 0)
>>> q.num_patterns()
1
>>> is_pattern(q.pattern(0))
True
>>> q.pattern(0)
f(Var(0))

Definition at line 2066 of file z3py.py.

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

Referenced by _mk_quantifier(), and _to_pattern().

◆ is_probe()

is_probe ( p)
Return `True` if `p` is a Z3 probe.

>>> is_probe(Int('x'))
False
>>> is_probe(Probe('memory'))
True

Definition at line 8991 of file z3py.py.

8991def is_probe(p):
8992 """Return `True` if `p` is a Z3 probe.
8993
8994 >>> is_probe(Int('x'))
8995 False
8996 >>> is_probe(Probe('memory'))
8997 True
8998 """
8999 return isinstance(p, Probe)
9000
9001

Referenced by _ctx_from_ast_arg_list(), _has_probe(), and Not().

◆ is_quantifier()

is_quantifier ( a)
Return `True` if `a` is a Z3 quantifier.

>>> f = Function('f', IntSort(), IntSort())
>>> x = Int('x')
>>> q = ForAll(x, f(x) == 0)
>>> is_quantifier(q)
True
>>> is_quantifier(f(x))
False

Definition at line 2316 of file z3py.py.

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

◆ is_rational_value()

is_rational_value ( a)
Return `True` if `a` is rational value of sort Real.

>>> is_rational_value(RealVal(1))
True
>>> is_rational_value(RealVal("3/5"))
True
>>> is_rational_value(IntVal(1))
False
>>> is_rational_value(1)
False
>>> n = Real('x') + 1
>>> n.arg(1)
1
>>> is_rational_value(n.arg(1))
True
>>> is_rational_value(Real('x'))
False

Definition at line 2899 of file z3py.py.

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

◆ is_re()

is_re ( s)

Definition at line 11579 of file z3py.py.

11579def is_re(s):
11580 return isinstance(s, ReRef)
11581
11582

Referenced by Concat().

◆ is_real()

is_real ( a)
Return `True` if `a` is a real expression.

>>> x = Int('x')
>>> is_real(x + 1)
False
>>> y = Real('y')
>>> is_real(y)
True
>>> is_real(y + 1)
True
>>> is_real(1)
False
>>> is_real(RealVal(1))
True

Definition at line 2848 of file z3py.py.

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

◆ is_select()

is_select ( a)
Return `True` if `a` is a Z3 array select application.

>>> a = Array('a', IntSort(), IntSort())
>>> is_select(a)
False
>>> i = Int('i')
>>> is_select(a[i])
True

Definition at line 5054 of file z3py.py.

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

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

11261def is_seq(a):
11262 """Return `True` if `a` is a Z3 sequence expression.
11263 >>> print (is_seq(Unit(IntVal(0))))
11264 True
11265 >>> print (is_seq(StringVal("abc")))
11266 True
11267 """
11268 return isinstance(a, SeqRef)
11269
11270

Referenced by Concat(), and Extract().

◆ is_sort()

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

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

Definition at line 682 of file z3py.py.

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

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

◆ is_store()

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

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

Definition at line 5067 of file z3py.py.

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

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

11271def is_string(a: Any) -> bool:
11272 """Return `True` if `a` is a Z3 string expression.
11273 >>> print (is_string(StringVal("ab")))
11274 True
11275 """
11276 return isinstance(a, SeqRef) and a.is_string()
11277
11278

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

11279def is_string_value(a: Any) -> bool:
11280 """return 'True' if 'a' is a Z3 string constant expression.
11281 >>> print (is_string_value(StringVal("a")))
11282 True
11283 >>> print (is_string_value(StringVal("a") + StringVal("b")))
11284 False
11285 """
11286 return isinstance(a, SeqRef) and a.is_string_value()
11287

◆ is_sub()

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

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

Definition at line 2959 of file z3py.py.

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

◆ is_to_int()

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

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

Definition at line 3087 of file z3py.py.

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

◆ is_to_real()

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

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

Definition at line 3072 of file z3py.py.

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

◆ is_true()

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

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

Definition at line 1722 of file z3py.py.

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

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

◆ is_var()

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

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

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

Definition at line 1413 of file z3py.py.

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

Referenced by get_var_index().

◆ IsInt()

IsInt ( a)
 Return the Z3 predicate IsInt(a).

>>> x = Real('x')
>>> IsInt(x + "1/2")
IsInt(x + 1/2)
>>> solve(IsInt(x + "1/2"), x > 0, x < 1)
[x = 1/2]
>>> solve(IsInt(x + "1/2"), x > 0, x < 1, x != "1/2")
no solution

Definition at line 3541 of file z3py.py.

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

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

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

5021def K(dom, v):
5022 """Return a Z3 constant array expression.
5023
5024 >>> a = K(IntSort(), 10)
5025 >>> a
5026 K(Int, 10)
5027 >>> a.sort()
5028 Array(Int, Int)
5029 >>> i = Int('i')
5030 >>> a[i]
5031 K(Int, 10)[i]
5032 >>> simplify(a[i])
5033 10
5034 """
5035 if z3_debug():
5036 _z3_assert(is_sort(dom), "Z3 sort expected")
5037 ctx = dom.ctx
5038 if not is_expr(v):
5039 v = _py2expr(v, ctx)
5040 return ArrayRef(Z3_mk_const_array(ctx.ref(), dom.ast, v.as_ast()), ctx)
5041
5042
Z3_ast Z3_API Z3_mk_const_array(Z3_context c, Z3_sort domain, Z3_ast v)
Create the constant array.

Referenced by ModelRef.get_interp().

◆ Lambda()

Lambda ( vs,
body )
Create a Z3 lambda expression.

>>> f = Function('f', IntSort(), IntSort(), IntSort())
>>> mem0 = Array('mem0', IntSort(), IntSort())
>>> lo, hi, e, i = Ints('lo hi e i')
>>> mem1 = Lambda([i], If(And(lo <= i, i <= hi), e, mem0[i]))
>>> mem1
Lambda(i, If(And(lo <= i, i <= hi), e, mem0[i]))

Definition at line 2404 of file z3py.py.

2404def Lambda(vs, body):
2405 """Create a Z3 lambda expression.
2406
2407 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2408 >>> mem0 = Array('mem0', IntSort(), IntSort())
2409 >>> lo, hi, e, i = Ints('lo hi e i')
2410 >>> mem1 = Lambda([i], If(And(lo <= i, i <= hi), e, mem0[i]))
2411 >>> mem1
2412 Lambda(i, If(And(lo <= i, i <= hi), e, mem0[i]))
2413 """
2414 ctx = body.ctx
2415 if is_app(vs):
2416 vs = [vs]
2417 num_vars = len(vs)
2418 _vs = (Ast * num_vars)()
2419 for i in range(num_vars):
2420 # TODO: Check if is constant
2421 _vs[i] = vs[i].as_ast()
2422 return QuantifierRef(Z3_mk_lambda_const(ctx.ref(), num_vars, _vs, body.as_ast()), ctx)
2423
Z3_ast Z3_API Z3_mk_lambda_const(Z3_context c, unsigned num_bound, Z3_app const bound[], Z3_ast body)
Create a lambda expression using a list of constants that form the set of bound variables.

◆ LastIndexOf()

LastIndexOf ( s,
substr )
Retrieve the last index of substring within a string

Definition at line 11464 of file z3py.py.

11464def LastIndexOf(s, substr):
11465 """Retrieve the last index of substring within a string"""
11466 ctx = None
11467 ctx = _get_ctx2(s, substr, ctx)
11468 s = _coerce_seq(s, ctx)
11469 substr = _coerce_seq(substr, ctx)
11470 return ArithRef(Z3_mk_seq_last_index(s.ctx_ref(), s.as_ast(), substr.as_ast()), s.ctx)
11471
11472
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 11473 of file z3py.py.

11473def Length(s):
11474 """Obtain the length of a sequence 's'
11475 >>> l = Length(StringVal("abc"))
11476 >>> simplify(l)
11477 3
11478 """
11479 s = _coerce_seq(s)
11480 return ArithRef(Z3_mk_seq_length(s.ctx_ref(), s.as_ast()), s.ctx)
11481
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 11735 of file z3py.py.

11735def LinearOrder(a, index):
11736 return FuncDeclRef(Z3_mk_linear_order(a.ctx_ref(), a.ast, index), a.ctx)
11737
11738
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 11685 of file z3py.py.

11685def Loop(re, lo, hi=0):
11686 """Create the regular expression accepting between a lower and upper bound repetitions
11687 >>> re = Loop(Re("a"), 1, 3)
11688 >>> print(simplify(InRe("aa", re)))
11689 True
11690 >>> print(simplify(InRe("aaaa", re)))
11691 False
11692 >>> print(simplify(InRe("", re)))
11693 False
11694 """
11695 if z3_debug():
11696 _z3_assert(is_expr(re), "expression expected")
11697 return ReRef(Z3_mk_re_loop(re.ctx_ref(), re.as_ast(), lo, hi), re.ctx)
11698
11699
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 4474 of file z3py.py.

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

4998def Map(f, *args):
4999 """Return a Z3 map array expression.
5000
5001 >>> f = Function('f', IntSort(), IntSort(), IntSort())
5002 >>> a1 = Array('a1', IntSort(), IntSort())
5003 >>> a2 = Array('a2', IntSort(), IntSort())
5004 >>> b = Map(f, a1, a2)
5005 >>> b
5006 Map(f, a1, a2)
5007 >>> prove(b[0] == f(a1[0], a2[0]))
5008 proved
5009 """
5010 args = _get_args(args)
5011 if z3_debug():
5012 _z3_assert(len(args) > 0, "At least one Z3 array expression expected")
5013 _z3_assert(is_func_decl(f), "First argument must be a Z3 function declaration")
5014 _z3_assert(all([is_array(a) for a in args]), "Z3 array expected expected")
5015 _z3_assert(len(args) == f.arity(), "Number of arguments mismatch")
5016 _args, sz = _to_ast_array(args)
5017 ctx = f.ctx
5018 return ArrayRef(Z3_mk_map(ctx.ref(), f.ast, sz, _args), ctx)
5019
5020
Z3_ast Z3_API Z3_mk_map(Z3_context c, Z3_func_decl f, unsigned n, Z3_ast const *args)
Map f on the argument arrays.

◆ mk_not()

mk_not ( a)

Definition at line 1967 of file z3py.py.

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

◆ Model()

Model ( ctx = None,
eval = {} )

Definition at line 6927 of file z3py.py.

6927def Model(ctx=None, eval = {}):
6928 ctx = _get_ctx(ctx)
6929 mdl = ModelRef(Z3_mk_model(ctx.ref()), ctx)
6930 for k, v in eval.items():
6931 mdl.update_value(k, v)
6932 return mdl
6933
6934
Z3_model Z3_API Z3_mk_model(Z3_context c)
Create a fresh model object. It has reference count 0.

◆ MultiPattern()

MultiPattern ( * args)
Create a Z3 multi-pattern using the given expressions `*args`

>>> f = Function('f', IntSort(), IntSort())
>>> g = Function('g', IntSort(), IntSort())
>>> x = Int('x')
>>> q = ForAll(x, f(x) != g(x), patterns = [ MultiPattern(f(x), g(x)) ])
>>> q
ForAll(x, f(x) != g(x))
>>> q.num_patterns()
1
>>> is_pattern(q.pattern(0))
True
>>> q.pattern(0)
MultiPattern(f(Var(0)), g(Var(0)))

Definition at line 2084 of file z3py.py.

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

Referenced by _to_pattern().

◆ Not()

Not ( a,
ctx = None )
Create a Z3 not expression or probe.

>>> p = Bool('p')
>>> Not(Not(p))
Not(Not(p))
>>> simplify(Not(Not(p)))
p

Definition at line 1948 of file z3py.py.

1948def Not(a, ctx=None):
1949 """Create a Z3 not expression or probe.
1950
1951 >>> p = Bool('p')
1952 >>> Not(Not(p))
1953 Not(Not(p))
1954 >>> simplify(Not(Not(p)))
1955 p
1956 """
1957 ctx = _get_ctx(_ctx_from_ast_arg_list([a], ctx))
1958 if is_probe(a):
1959 # Not is also used to build probes
1960 return Probe(Z3_probe_not(ctx.ref(), a.probe), ctx)
1961 else:
1962 s = BoolSort(ctx)
1963 a = s.cast(a)
1964 return BoolRef(Z3_mk_not(ctx.ref(), a.as_ast()), ctx)
1965
1966
Z3_probe Z3_API Z3_probe_not(Z3_context x, Z3_probe p)
Return a probe that evaluates to "true" when p does not evaluate to true.
Z3_ast Z3_API Z3_mk_not(Z3_context c, Z3_ast a)
Create an AST node representing not(a).

Referenced by BoolRef.__invert__(), and mk_not().

◆ on_clause_eh()

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

Definition at line 11775 of file z3py.py.

11775def on_clause_eh(ctx, p, n, dep, clause):
11776 onc = _my_hacky_class
11777 p = _to_expr_ref(to_Ast(p), onc.ctx)
11778 clause = AstVector(to_AstVectorObj(clause), onc.ctx)
11779 deps = [dep[i] for i in range(n)]
11780 onc.on_clause(p, deps, clause)
11781

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

11650def Option(re):
11651 """Create the regular expression that optionally accepts the argument.
11652 >>> re = Option(Re("a"))
11653 >>> print(simplify(InRe("a", re)))
11654 True
11655 >>> print(simplify(InRe("", re)))
11656 True
11657 >>> print(simplify(InRe("aa", re)))
11658 False
11659 """
11660 if z3_debug():
11661 _z3_assert(is_expr(re), "expression expected")
11662 return ReRef(Z3_mk_re_option(re.ctx_ref(), re.as_ast()), re.ctx)
11663
11664
Z3_ast Z3_API Z3_mk_re_option(Z3_context c, Z3_ast re)
Create the regular language [re].

◆ Or()

Or ( * args)
Create a Z3 or-expression or or-probe.

>>> p, q, r = Bools('p q r')
>>> Or(p, q, r)
Or(p, q, r)
>>> P = BoolVector('p', 5)
>>> Or(P)
Or(p__0, p__1, p__2, p__3, p__4)

Definition at line 2015 of file z3py.py.

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

Referenced by BoolRef.__or__().

◆ OrElse()

OrElse ( * ts,
** ks )
Return a tactic that applies the tactics in `*ts` until one of them succeeds (it doesn't fail).

>>> x = Int('x')
>>> t = OrElse(Tactic('split-clause'), Tactic('skip'))
>>> # Tactic split-clause fails if there is no clause in the given goal.
>>> t(x == 0)
[[x == 0]]
>>> t(Or(x == 0, x == 1))
[[x == 0], [x == 1]]

Definition at line 8684 of file z3py.py.

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

◆ ParAndThen()

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

Definition at line 8740 of file z3py.py.

8740def ParAndThen(t1, t2, ctx=None):
8741 """Alias for ParThen(t1, t2, ctx)."""
8742 return ParThen(t1, t2, ctx)
8743
8744

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

8705def ParOr(*ts, **ks):
8706 """Return a tactic that applies the tactics in `*ts` in parallel until one of them succeeds (it doesn't fail).
8707
8708 >>> x = Int('x')
8709 >>> t = ParOr(Tactic('simplify'), Tactic('fail'))
8710 >>> t(x + 1 == 2)
8711 [[x == 1]]
8712 """
8713 if z3_debug():
8714 _z3_assert(len(ts) >= 2, "At least two arguments expected")
8715 ctx = _get_ctx(ks.get("ctx", None))
8716 ts = [_to_tactic(t, ctx) for t in ts]
8717 sz = len(ts)
8718 _args = (TacticObj * sz)()
8719 for i in range(sz):
8720 _args[i] = ts[i].tactic
8721 return Tactic(Z3_tactic_par_or(ctx.ref(), sz, _args), ctx)
8722
8723
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 9620 of file z3py.py.

9620def parse_smt2_file(f, sorts={}, decls={}, ctx=None):
9621 """Parse a file in SMT 2.0 format using the given sorts and decls.
9622
9623 This function is similar to parse_smt2_string().
9624 """
9625 ctx = _get_ctx(ctx)
9626 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
9627 dsz, dnames, ddecls = _dict2darray(decls, ctx)
9628 return AstVector(Z3_parse_smtlib2_file(ctx.ref(), f, ssz, snames, ssorts, dsz, dnames, ddecls), ctx)
9629
9630
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 9599 of file z3py.py.

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

8724def ParThen(t1, t2, ctx=None):
8725 """Return a tactic that applies t1 and then t2 to every subgoal produced by t1.
8726 The subgoals are processed in parallel.
8727
8728 >>> x, y = Ints('x y')
8729 >>> t = ParThen(Tactic('split-clause'), Tactic('propagate-values'))
8730 >>> t(And(Or(x == 1, x == 2), y == x + 1))
8731 [[x == 1, y == 2], [x == 2, y == 3]]
8732 """
8733 t1 = _to_tactic(t1, ctx)
8734 t2 = _to_tactic(t2, ctx)
8735 if z3_debug():
8736 _z3_assert(t1.ctx == t2.ctx, "Context mismatch")
8737 return Tactic(Z3_tactic_par_and_then(t1.ctx.ref(), t1.tactic, t2.tactic), t1.ctx)
8738
8739
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 11731 of file z3py.py.

11731def PartialOrder(a, index):
11732 return FuncDeclRef(Z3_mk_partial_order(a.ctx_ref(), a.ast, index), a.ctx)
11733
11734
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 9376 of file z3py.py.

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

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

9354def PbLe(args, k):
9355 """Create a Pseudo-Boolean inequality k constraint.
9356
9357 >>> a, b, c = Bools('a b c')
9358 >>> f = PbLe(((a,1),(b,3),(c,2)), 3)
9359 """
9360 _z3_check_cint_overflow(k, "k")
9361 ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
9362 return BoolRef(Z3_mk_pble(ctx.ref(), sz, _args, _coeffs, k), ctx)
9363
9364
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 11743 of file z3py.py.

11743def PiecewiseLinearOrder(a, index):
11744 return FuncDeclRef(Z3_mk_piecewise_linear_order(a.ctx_ref(), a.ast, index), a.ctx)
11745
11746
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 11635 of file z3py.py.

11635def Plus(re):
11636 """Create the regular expression accepting one or more repetitions of argument.
11637 >>> re = Plus(Re("a"))
11638 >>> print(simplify(InRe("aa", re)))
11639 True
11640 >>> print(simplify(InRe("ab", re)))
11641 False
11642 >>> print(simplify(InRe("", re)))
11643 False
11644 """
11645 if z3_debug():
11646 _z3_assert(is_expr(re), "expression expected")
11647 return ReRef(Z3_mk_re_plus(re.ctx_ref(), re.as_ast()), re.ctx)
11648
11649
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 11380 of file z3py.py.

11380def PrefixOf(a, b):
11381 """Check if 'a' is a prefix of 'b'
11382 >>> s1 = PrefixOf("ab", "abc")
11383 >>> simplify(s1)
11384 True
11385 >>> s2 = PrefixOf("bc", "abc")
11386 >>> simplify(s2)
11387 False
11388 """
11389 ctx = _get_ctx2(a, b)
11390 a = _coerce_seq(a, ctx)
11391 b = _coerce_seq(b, ctx)
11392 return BoolRef(Z3_mk_seq_prefix(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
11393
11394
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 9020 of file z3py.py.

9020def probe_description(name, ctx=None):
9021 """Return a short description for the probe named `name`.
9022
9023 >>> d = probe_description('memory')
9024 """
9025 ctx = _get_ctx(ctx)
9026 return Z3_probe_get_descr(ctx.ref(), name)
9027
9028
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 9009 of file z3py.py.

9009def probes(ctx=None):
9010 """Return a list of all available probes in Z3.
9011
9012 >>> l = probes()
9013 >>> l.count('memory') == 1
9014 True
9015 """
9016 ctx = _get_ctx(ctx)
9017 return [Z3_get_probe_name(ctx.ref(), i) for i in range(Z3_get_num_probes(ctx.ref()))]
9018
9019
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 9261 of file z3py.py.

9261def Product(*args):
9262 """Create the product of the Z3 expressions.
9263
9264 >>> a, b, c = Ints('a b c')
9265 >>> Product(a, b, c)
9266 a*b*c
9267 >>> Product([a, b, c])
9268 a*b*c
9269 >>> A = IntVector('a', 5)
9270 >>> Product(A)
9271 a__0*a__1*a__2*a__3*a__4
9272 """
9273 args = _get_args(args)
9274 if len(args) == 0:
9275 return 1
9276 ctx = _ctx_from_ast_arg_list(args)
9277 if ctx is None:
9278 return _reduce(lambda a, b: a * b, args, 1)
9279 args = _coerce_expr_list(args, ctx)
9280 if is_bv(args[0]):
9281 return _reduce(lambda a, b: a * b, args, 1)
9282 else:
9283 _args, sz = _to_ast_array(args)
9284 return ArithRef(Z3_mk_mul(ctx.ref(), sz, _args), ctx)
9285
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 11940 of file z3py.py.

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

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

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

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

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

11700def Range(lo, hi, ctx=None):
11701 """Create the range regular expression over two sequences of length 1
11702 >>> range = Range("a","z")
11703 >>> print(simplify(InRe("b", range)))
11704 True
11705 >>> print(simplify(InRe("bb", range)))
11706 False
11707 """
11708 lo = _coerce_seq(lo, ctx)
11709 hi = _coerce_seq(hi, ctx)
11710 if z3_debug():
11711 _z3_assert(is_expr(lo), "expression expected")
11712 _z3_assert(is_expr(hi), "expression expected")
11713 return ReRef(Z3_mk_re_range(lo.ctx_ref(), lo.ast, hi.ast), lo.ctx)
11714
Z3_ast Z3_API Z3_mk_re_range(Z3_context c, Z3_ast lo, Z3_ast hi)
Create the range regular expression over two sequences of length 1.

◆ RatVal()

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

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

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

Definition at line 3364 of file z3py.py.

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

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

11544def Re(s, ctx=None):
11545 """The regular expression that accepts sequence 's'
11546 >>> s1 = Re("ab")
11547 >>> s2 = Re(StringVal("ab"))
11548 >>> s3 = Re(Unit(BoolVal(True)))
11549 """
11550 s = _coerce_seq(s, ctx)
11551 return ReRef(Z3_mk_seq_to_re(s.ctx_ref(), s.as_ast()), s.ctx)
11552
11553
11554# Regular expressions
11555
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 3446 of file z3py.py.

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

Referenced by Reals(), and RealVector().

◆ Reals()

Reals ( names,
ctx = None )
Return a tuple of real constants.

>>> x, y, z = Reals('x y z')
>>> Sum(x, y, z)
x + y + z
>>> Sum(x, y, z).sort()
Real

Definition at line 3459 of file z3py.py.

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

◆ RealSort()

RealSort ( ctx = None)
Return the real sort in the given context. If `ctx=None`, then the global context is used.

>>> RealSort()
Real
>>> x = Const('x', RealSort())
>>> is_real(x)
True
>>> is_int(x)
False
>>> x.sort() == RealSort()
True

Definition at line 3304 of file z3py.py.

3304def RealSort(ctx=None):
3305 """Return the real sort in the given context. If `ctx=None`, then the global context is used.
3306
3307 >>> RealSort()
3308 Real
3309 >>> x = Const('x', RealSort())
3310 >>> is_real(x)
3311 True
3312 >>> is_int(x)
3313 False
3314 >>> x.sort() == RealSort()
3315 True
3316 """
3317 ctx = _get_ctx(ctx)
3318 return ArithSortRef(Z3_mk_real_sort(ctx.ref()), ctx)
3319
3320
Z3_sort Z3_API Z3_mk_real_sort(Z3_context c)
Create the real type.

Referenced by FreshReal(), Real(), RealVal(), and RealVar().

◆ RealVal()

RealVal ( val,
ctx = None )
Return a Z3 real value.

`val` may be a Python int, long, float or string representing a number in decimal or rational notation.
If `ctx=None`, then the global context is used.

>>> RealVal(1)
1
>>> RealVal(1).sort()
Real
>>> RealVal("3/5")
3/5
>>> RealVal("1.5")
3/2

Definition at line 3345 of file z3py.py.

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

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

◆ RealVar()

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

>>> RealVar(0)
Var(0)

Definition at line 1590 of file z3py.py.

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

Referenced by RealVarVector().

◆ RealVarVector()

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

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

Definition at line 1600 of file z3py.py.

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

◆ RealVector()

RealVector ( prefix,
sz,
ctx = None )
Return a list of real constants of size `sz`.

>>> X = RealVector('x', 3)
>>> X
[x__0, x__1, x__2]
>>> Sum(X)
x__0 + x__1 + x__2
>>> Sum(X).sort()
Real

Definition at line 3474 of file z3py.py.

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

◆ RecAddDefinition()

RecAddDefinition ( f,
args,
body )
Set the body of a recursive function.
   Recursive definitions can be simplified if they are applied to ground
   arguments.
>>> ctx = Context()
>>> fac = RecFunction('fac', IntSort(ctx), IntSort(ctx))
>>> n = Int('n', ctx)
>>> RecAddDefinition(fac, n, If(n == 0, 1, n*fac(n-1)))
>>> simplify(fac(5))
120
>>> s = Solver(ctx=ctx)
>>> s.add(fac(n) < 3)
>>> s.check()
sat
>>> s.model().eval(fac(5))
120

Definition at line 984 of file z3py.py.

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

◆ RecFunction()

RecFunction ( name,
* sig )
Create a new Z3 recursive with the given sorts.

Definition at line 966 of file z3py.py.

966def RecFunction(name, *sig):
967 """Create a new Z3 recursive with the given sorts."""
968 sig = _get_args(sig)
969 if z3_debug():
970 _z3_assert(len(sig) > 0, "At least two arguments expected")
971 arity = len(sig) - 1
972 rng = sig[arity]
973 if z3_debug():
974 _z3_assert(is_sort(rng), "Z3 sort expected")
975 dom = (Sort * arity)()
976 for i in range(arity):
977 if z3_debug():
978 _z3_assert(is_sort(sig[i]), "Z3 sort expected")
979 dom[i] = sig[i].ast
980 ctx = rng.ctx
981 return FuncDeclRef(Z3_mk_rec_func_decl(ctx.ref(), to_symbol(name, ctx), arity, dom, rng.ast), ctx)
982
983
Z3_func_decl Z3_API Z3_mk_rec_func_decl(Z3_context c, Z3_symbol s, unsigned domain_size, Z3_sort const domain[], Z3_sort range)
Declare a recursive function.

◆ Repeat()

Repeat ( t,
max = 4294967295,
ctx = None )
Return a tactic that keeps applying `t` until the goal is not modified anymore
or the maximum number of iterations `max` is reached.

>>> x, y = Ints('x y')
>>> c = And(Or(x == 0, x == 1), Or(y == 0, y == 1), x > y)
>>> t = Repeat(OrElse(Tactic('split-clause'), Tactic('skip')))
>>> r = t(c)
>>> for subgoal in r: print(subgoal)
[x == 0, y == 0, x > y]
[x == 0, y == 1, x > y]
[x == 1, y == 0, x > y]
[x == 1, y == 1, x > y]
>>> t = Then(t, Tactic('propagate-values'))
>>> t(c)
[[x == 1, y == 0]]

Definition at line 8773 of file z3py.py.

8773def Repeat(t, max=4294967295, ctx=None):
8774 """Return a tactic that keeps applying `t` until the goal is not modified anymore
8775 or the maximum number of iterations `max` is reached.
8776
8777 >>> x, y = Ints('x y')
8778 >>> c = And(Or(x == 0, x == 1), Or(y == 0, y == 1), x > y)
8779 >>> t = Repeat(OrElse(Tactic('split-clause'), Tactic('skip')))
8780 >>> r = t(c)
8781 >>> for subgoal in r: print(subgoal)
8782 [x == 0, y == 0, x > y]
8783 [x == 0, y == 1, x > y]
8784 [x == 1, y == 0, x > y]
8785 [x == 1, y == 1, x > y]
8786 >>> t = Then(t, Tactic('propagate-values'))
8787 >>> t(c)
8788 [[x == 1, y == 0]]
8789 """
8790 t = _to_tactic(t, ctx)
8791 return Tactic(Z3_tactic_repeat(t.ctx.ref(), t.tactic, max), t.ctx)
8792
8793
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 4596 of file z3py.py.

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

11429def Replace(s, src, dst):
11430 """Replace the first occurrence of 'src' by 'dst' in 's'
11431 >>> r = Replace("aaa", "a", "b")
11432 >>> simplify(r)
11433 "baa"
11434 """
11435 ctx = _get_ctx2(dst, s)
11436 if ctx is None and is_expr(src):
11437 ctx = src.ctx
11438 src = _coerce_seq(src, ctx)
11439 dst = _coerce_seq(dst, ctx)
11440 s = _coerce_seq(s, ctx)
11441 return SeqRef(Z3_mk_seq_replace(src.ctx_ref(), s.as_ast(), src.as_ast(), dst.as_ast()), s.ctx)
11442
11443
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 11563 of file z3py.py.

11563def ReSort(s):
11564 if is_ast(s):
11565 return ReSortRef(Z3_mk_re_sort(s.ctx.ref(), s.ast), s.ctx)
11566 if s is None or isinstance(s, Context):
11567 ctx = _get_ctx(s)
11568 return ReSortRef(Z3_mk_re_sort(ctx.ref(), Z3_mk_string_sort(ctx.ref())), s.ctx)
11569 raise Z3Exception("Regular expression sort constructor expects either a string or a context or no argument")
11570
11571
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 10035 of file z3py.py.

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

10025def RNE(ctx=None):
10026 ctx = _get_ctx(ctx)
10027 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_even(ctx.ref()), ctx)
10028
10029
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 4506 of file z3py.py.

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

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

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

◆ RoundNearestTiesToEven()

RoundNearestTiesToEven ( ctx = None)

Definition at line 10020 of file z3py.py.

10020def RoundNearestTiesToEven(ctx=None):
10021 ctx = _get_ctx(ctx)
10022 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_even(ctx.ref()), ctx)
10023
10024

◆ RoundTowardNegative()

RoundTowardNegative ( ctx = None)

Definition at line 10050 of file z3py.py.

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

10040def RoundTowardPositive(ctx=None):
10041 ctx = _get_ctx(ctx)
10042 return FPRMRef(Z3_mk_fpa_round_toward_positive(ctx.ref()), ctx)
10043
10044
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 10060 of file z3py.py.

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

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

◆ RTP()

RTP ( ctx = None)

Definition at line 10045 of file z3py.py.

10045def RTP(ctx=None):
10046 ctx = _get_ctx(ctx)
10047 return FPRMRef(Z3_mk_fpa_round_toward_positive(ctx.ref()), ctx)
10048
10049

◆ RTZ()

RTZ ( ctx = None)

Definition at line 10065 of file z3py.py.

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

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

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

◆ SeqFoldLeft()

SeqFoldLeft ( f,
a,
s )

Definition at line 11496 of file z3py.py.

11496def SeqFoldLeft(f, a, s):
11497 ctx = _get_ctx2(f, s)
11498 s = _coerce_seq(s, ctx)
11499 a = _py2expr(a)
11500 return _to_expr_ref(Z3_mk_seq_foldl(s.ctx_ref(), f.as_ast(), a.as_ast(), s.as_ast()), ctx)
11501
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 11502 of file z3py.py.

11502def SeqFoldLeftI(f, i, a, s):
11503 ctx = _get_ctx2(f, s)
11504 s = _coerce_seq(s, ctx)
11505 a = _py2expr(a)
11506 i = _py2expr(i)
11507 return _to_expr_ref(Z3_mk_seq_foldli(s.ctx_ref(), f.as_ast(), i.as_ast(), a.as_ast(), s.as_ast()), ctx)
11508
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 11482 of file z3py.py.

11482def SeqMap(f, s):
11483 """Map function 'f' over sequence 's'"""
11484 ctx = _get_ctx2(f, s)
11485 s = _coerce_seq(s, ctx)
11486 return _to_expr_ref(Z3_mk_seq_map(s.ctx_ref(), f.as_ast(), s.as_ast()), ctx)
11487
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 11488 of file z3py.py.

11488def SeqMapI(f, i, s):
11489 """Map function 'f' over sequence 's' at index 'i'"""
11490 ctx = _get_ctx2(f, s)
11491 s = _coerce_seq(s, ctx)
11492 if not is_expr(i):
11493 i = _py2expr(i)
11494 return _to_expr_ref(Z3_mk_seq_mapi(s.ctx_ref(), f.as_ast(), i.as_ast(), s.as_ast()), ctx)
11495
Z3_ast Z3_API Z3_mk_seq_mapi(Z3_context c, Z3_ast f, Z3_ast i, Z3_ast s)
Create a map of the function f over the sequence s starting at index i.

◆ SeqSort()

SeqSort ( s)
Create a sequence sort over elements provided in the argument
>>> s = SeqSort(IntSort())
>>> s == Unit(IntVal(1)).sort()
True

Definition at line 11129 of file z3py.py.

11129def SeqSort(s):
11130 """Create a sequence sort over elements provided in the argument
11131 >>> s = SeqSort(IntSort())
11132 >>> s == Unit(IntVal(1)).sort()
11133 True
11134 """
11135 return SeqSortRef(Z3_mk_seq_sort(s.ctx_ref(), s.ast), s.ctx)
11136
11137
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 9681 of file z3py.py.

9681def set_default_fp_sort(ebits, sbits, ctx=None):
9682 global _dflt_fpsort_ebits
9683 global _dflt_fpsort_sbits
9684 _dflt_fpsort_ebits = ebits
9685 _dflt_fpsort_sbits = sbits
9686
9687

◆ set_default_rounding_mode()

set_default_rounding_mode ( rm,
ctx = None )

Definition at line 9668 of file z3py.py.

9668def set_default_rounding_mode(rm, ctx=None):
9669 global _dflt_rounding_mode
9670 if is_fprm_value(rm):
9671 _dflt_rounding_mode = rm.kind()
9672 else:
9673 _z3_assert(_dflt_rounding_mode in _ROUNDING_MODES, "illegal rounding mode")
9674 _dflt_rounding_mode = rm
9675
9676

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

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

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

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

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

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

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

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

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

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

7700def SimpleSolver(ctx=None, logFile=None):
7701 """Return a simple general purpose solver with limited amount of preprocessing.
7702
7703 >>> s = SimpleSolver()
7704 >>> x = Int('x')
7705 >>> s.add(x > 0)
7706 >>> s.check()
7707 sat
7708 """
7709 ctx = _get_ctx(ctx)
7710 return Solver(Z3_mk_simple_solver(ctx.ref()), ctx, logFile)
7711
Z3_solver Z3_API Z3_mk_simple_solver(Z3_context c)
Create a new incremental solver.

◆ simplify()

simplify ( a,
* arguments,
** keywords )

Utils.

Simplify the expression `a` using the given options.

This function has many options. Use `help_simplify` to obtain the complete list.

>>> x = Int('x')
>>> y = Int('y')
>>> simplify(x + 1 + y + x + 1)
2 + 2*x + y
>>> simplify((x + 1)*(y + 1), som=True)
1 + x + y + x*y
>>> simplify(Distinct(x, y, 1), blast_distinct=True)
And(Not(x == y), Not(x == 1), Not(y == 1))
>>> simplify(And(x == 0, y == 1), elim_and=True)
Not(Or(Not(x == 0), Not(y == 1)))

Definition at line 9125 of file z3py.py.

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

9155def simplify_param_descrs():
9156 """Return the set of parameter descriptions for Z3 `simplify` procedure."""
9157 return ParamDescrsRef(Z3_simplify_get_param_descrs(main_ctx().ref()), main_ctx())
9158
9159
Z3_param_descrs Z3_API Z3_simplify_get_param_descrs(Z3_context c)
Return the parameter description set for the simplify procedure.

◆ solve()

solve ( * args,
** keywords )
Solve the constraints `*args`.

This is a simple function for creating demonstrations. It creates a solver,
configure it using the options in `keywords`, adds the constraints
in `args`, and invokes check.

>>> a = Int('a')
>>> solve(a > 0, a < 2)
[a = 1]

Definition at line 9387 of file z3py.py.

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

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

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

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

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

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

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

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

11670def Star(re):
11671 """Create the regular expression accepting zero or more repetitions of argument.
11672 >>> re = Star(Re("a"))
11673 >>> print(simplify(InRe("aa", re)))
11674 True
11675 >>> print(simplify(InRe("ab", re)))
11676 False
11677 >>> print(simplify(InRe("", re)))
11678 True
11679 """
11680 if z3_debug():
11681 _z3_assert(is_expr(re), "expression expected")
11682 return ReRef(Z3_mk_re_star(re.ctx_ref(), re.as_ast()), re.ctx)
11683
11684
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 4965 of file z3py.py.

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

Referenced by ModelRef.get_interp().

◆ StrFromCode()

StrFromCode ( c)
Convert code to a string

Definition at line 11538 of file z3py.py.

11538def StrFromCode(c):
11539 """Convert code to a string"""
11540 if not is_expr(c):
11541 c = _py2expr(c)
11542 return SeqRef(Z3_mk_string_from_code(c.ctx_ref(), c.as_ast()), c.ctx)
11543
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 11295 of file z3py.py.

11295def String(name, ctx=None):
11296 """Return a string constant named `name`. If `ctx=None`, then the global context is used.
11297
11298 >>> x = String('x')
11299 """
11300 ctx = _get_ctx(ctx)
11301 return SeqRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), StringSort(ctx).ast), ctx)
11302
11303

◆ Strings()

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

Definition at line 11304 of file z3py.py.

11304def Strings(names, ctx=None):
11305 """Return a tuple of String constants. """
11306 ctx = _get_ctx(ctx)
11307 if isinstance(names, str):
11308 names = names.split(" ")
11309 return [String(name, ctx) for name in names]
11310
11311

◆ StringSort()

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

Definition at line 11110 of file z3py.py.

11110def StringSort(ctx=None):
11111 """Create a string sort
11112 >>> s = StringSort()
11113 >>> print(s)
11114 String
11115 """
11116 ctx = _get_ctx(ctx)
11117 return SeqSortRef(Z3_mk_string_sort(ctx.ref()), ctx)
11118

◆ StringVal()

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

Definition at line 11288 of file z3py.py.

11288def StringVal(s, ctx=None):
11289 """create a string expression"""
11290 s = "".join(str(ch) if 32 <= ord(ch) and ord(ch) < 127 else "\\u{%x}" % (ord(ch)) for ch in s)
11291 ctx = _get_ctx(ctx)
11292 return SeqRef(Z3_mk_string(ctx.ref(), s), ctx)
11293
11294
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 11532 of file z3py.py.

11532def StrToCode(s):
11533 """Convert a unit length string to integer code"""
11534 if not is_expr(s):
11535 s = _py2expr(s)
11536 return ArithRef(Z3_mk_string_to_code(s.ctx_ref(), s.as_ast()), s.ctx)
11537
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 11509 of file z3py.py.

11509def StrToInt(s):
11510 """Convert string expression to integer
11511 >>> a = StrToInt("1")
11512 >>> simplify(1 == a)
11513 True
11514 >>> b = StrToInt("2")
11515 >>> simplify(1 == b)
11516 False
11517 >>> c = StrToInt(IntToStr(2))
11518 >>> simplify(1 == c)
11519 False
11520 """
11521 s = _coerce_seq(s)
11522 return ArithRef(Z3_mk_str_to_int(s.ctx_ref(), s.as_ast()), s.ctx)
11523
11524
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 11326 of file z3py.py.

11326def SubSeq(s, offset, length):
11327 """Extract substring or subsequence starting at offset.
11328
11329 This is a convenience function that redirects to Extract(s, offset, length).
11330
11331 >>> s = StringVal("hello world")
11332 >>> SubSeq(s, 0, 5) # Extract "hello"
11333 str.substr("hello world", 0, 5)
11334 >>> simplify(SubSeq(StringVal("testing"), 2, 4))
11335 "stin"
11336 """
11337 return Extract(s, offset, length)
11338
11339

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

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

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

9193def substitute_vars(t, *m):
9194 """Substitute the free variables in t with the expression in m.
9195
9196 >>> v0 = Var(0, IntSort())
9197 >>> v1 = Var(1, IntSort())
9198 >>> x = Int('x')
9199 >>> f = Function('f', IntSort(), IntSort(), IntSort())
9200 >>> # replace v0 with x+1 and v1 with x
9201 >>> substitute_vars(f(v0, v1), x + 1, x)
9202 f(x + 1, x)
9203 """
9204 if z3_debug():
9205 _z3_assert(is_expr(t), "Z3 expression expected")
9206 _z3_assert(all([is_expr(n) for n in m]), "Z3 invalid substitution, list of expressions expected.")
9207 num = len(m)
9208 _to = (Ast * num)()
9209 for i in range(num):
9210 _to[i] = m[i].as_ast()
9211 return _to_expr_ref(Z3_substitute_vars(t.ctx.ref(), t.as_ast(), num, _to), t.ctx)
9212
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 11312 of file z3py.py.

11312def SubString(s, offset, length):
11313 """Extract substring or subsequence starting at offset.
11314
11315 This is a convenience function that redirects to Extract(s, offset, length).
11316
11317 >>> s = StringVal("hello world")
11318 >>> SubString(s, 6, 5) # Extract "world"
11319 str.substr("hello world", 6, 5)
11320 >>> simplify(SubString(StringVal("hello"), 1, 3))
11321 "ell"
11322 """
11323 return Extract(s, offset, length)
11324
11325

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

11395def SuffixOf(a, b):
11396 """Check if 'a' is a suffix of 'b'
11397 >>> s1 = SuffixOf("ab", "abc")
11398 >>> simplify(s1)
11399 False
11400 >>> s2 = SuffixOf("bc", "abc")
11401 >>> simplify(s2)
11402 True
11403 """
11404 ctx = _get_ctx2(a, b)
11405 a = _coerce_seq(a, ctx)
11406 b = _coerce_seq(b, ctx)
11407 return BoolRef(Z3_mk_seq_suffix(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
11408
11409
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 9235 of file z3py.py.

9235def Sum(*args):
9236 """Create the sum of the Z3 expressions.
9237
9238 >>> a, b, c = Ints('a b c')
9239 >>> Sum(a, b, c)
9240 a + b + c
9241 >>> Sum([a, b, c])
9242 a + b + c
9243 >>> A = IntVector('a', 5)
9244 >>> Sum(A)
9245 a__0 + a__1 + a__2 + a__3 + a__4
9246 """
9247 args = _get_args(args)
9248 if len(args) == 0:
9249 return 0
9250 ctx = _ctx_from_ast_arg_list(args)
9251 if ctx is None:
9252 return _reduce(lambda a, b: a + b, args, 0)
9253 args = _coerce_expr_list(args, ctx)
9254 if is_bv(args[0]):
9255 return _reduce(lambda a, b: a + b, args, 0)
9256 else:
9257 _args, sz = _to_ast_array(args)
9258 return ArithRef(Z3_mk_add(ctx.ref(), sz, _args), ctx)
9259
9260
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 8814 of file z3py.py.

8814def tactic_description(name, ctx=None):
8815 """Return a short description for the tactic named `name`.
8816
8817 >>> d = tactic_description('simplify')
8818 """
8819 ctx = _get_ctx(ctx)
8820 return Z3_tactic_get_descr(ctx.ref(), name)
8821
8822
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 8803 of file z3py.py.

8803def tactics(ctx=None):
8804 """Return a list of all available tactics in Z3.
8805
8806 >>> l = tactics()
8807 >>> l.count('simplify') == 1
8808 True
8809 """
8810 ctx = _get_ctx(ctx)
8811 return [Z3_get_tactic_name(ctx.ref(), i) for i in range(Z3_get_num_tactics(ctx.ref()))]
8812
8813
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 8671 of file z3py.py.

8671def Then(*ts, **ks):
8672 """Return a tactic that applies the tactics in `*ts` in sequence. Shorthand for AndThen(*ts, **ks).
8673
8674 >>> x, y = Ints('x y')
8675 >>> t = Then(Tactic('simplify'), Tactic('solve-eqs'))
8676 >>> t(And(x == 0, y > x + 1))
8677 [[Not(y <= 1)]]
8678 >>> t(And(x == 0, y > x + 1)).as_expr()
8679 Not(y <= 1)
8680 """
8681 return AndThen(*ts, **ks)
8682
8683

◆ to_Ast()

to_Ast ( ptr)

Definition at line 11754 of file z3py.py.

11754def to_Ast(ptr,):
11755 ast = Ast(ptr)
11756 super(ctypes.c_void_p, ast).__init__(ptr)
11757 return ast
11758

◆ to_AstVectorObj()

to_AstVectorObj ( ptr)

Definition at line 11764 of file z3py.py.

11764def to_AstVectorObj(ptr,):
11765 v = AstVectorObj(ptr)
11766 super(ctypes.c_void_p, v).__init__(ptr)
11767 return v
11768
11769# NB. my-hacky-class only works for a single instance of OnClause
11770# it should be replaced with a proper correlation between OnClause
11771# and object references that can be passed over the FFI.
11772# for UserPropagator we use a global dictionary, which isn't great code.
11773

◆ to_ContextObj()

to_ContextObj ( ptr)

Definition at line 11759 of file z3py.py.

11759def to_ContextObj(ptr,):
11760 ctx = ContextObj(ptr)
11761 super(ctypes.c_void_p, ctx).__init__(ptr)
11762 return ctx
11763

◆ to_symbol()

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

Definition at line 132 of file z3py.py.

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

Referenced by _mk_quantifier(), Array(), BitVec(), Bool(), Const(), CreateDatatypes(), DatatypeSort(), DeclareSort(), DeclareTypeVar(), EnumSort(), Function(), ParamDescrsRef.get_documentation(), ParamDescrsRef.get_kind(), Int(), Real(), RecFunction(), and ParamsRef.set().

◆ ToInt()

ToInt ( a)
 Return the Z3 expression ToInt(a).

>>> x = Real('x')
>>> x.sort()
Real
>>> n = ToInt(x)
>>> n
ToInt(x)
>>> n.sort()
Int

Definition at line 3523 of file z3py.py.

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

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

11747def TransitiveClosure(f):
11748 """Given a binary relation R, such that the two arguments have the same sort
11749 create the transitive closure relation R+.
11750 The transitive closure R+ is a new relation.
11751 """
11752 return FuncDeclRef(Z3_mk_transitive_closure(f.ctx_ref(), f.ast), f.ctx)
11753
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 11739 of file z3py.py.

11739def TreeOrder(a, index):
11740 return FuncDeclRef(Z3_mk_tree_order(a.ctx_ref(), a.ast, index), a.ctx)
11741
11742
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 8794 of file z3py.py.

8794def TryFor(t, ms, ctx=None):
8795 """Return a tactic that applies `t` to a given goal for `ms` milliseconds.
8796
8797 If `t` does not terminate in `ms` milliseconds, then it fails.
8798 """
8799 t = _to_tactic(t, ctx)
8800 return Tactic(Z3_tactic_try_for(t.ctx.ref(), t.tactic, ms), t.ctx)
8801
8802
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 5577 of file z3py.py.

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

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

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

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

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

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

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

11597def Union(*args):
11598 """Create union of regular expressions.
11599 >>> re = Union(Re("a"), Re("b"), Re("c"))
11600 >>> print (simplify(InRe("d", re)))
11601 False
11602 """
11603 args = _get_args(args)
11604 sz = len(args)
11605 if z3_debug():
11606 _z3_assert(sz > 0, "At least one argument expected.")
11607 _z3_assert(all([is_re(a) for a in args]), "All arguments must be regular expressions.")
11608 if sz == 1:
11609 return args[0]
11610 ctx = args[0].ctx
11611 v = (Ast * sz)()
11612 for i in range(sz):
11613 v[i] = args[i].as_ast()
11614 return ReRef(Z3_mk_re_union(ctx.ref(), sz, v), ctx)
11615
11616
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 11375 of file z3py.py.

11375def Unit(a):
11376 """Create a singleton sequence"""
11377 return SeqRef(Z3_mk_seq_unit(a.ctx_ref(), a.as_ast()), a.ctx)
11378
11379
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 4922 of file z3py.py.

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

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

11917def user_prop_binding(ctx, cb, q_ref, inst_ref):
11918 prop = _prop_closures.get(ctx)
11919 old_cb = prop.cb
11920 prop.cb = cb
11921 q = _to_expr_ref(to_Ast(q_ref), prop.ctx())
11922 inst = _to_expr_ref(to_Ast(inst_ref), prop.ctx())
11923 r = prop.binding(q, inst)
11924 prop.cb = old_cb
11925 return r
11926
11927

◆ user_prop_created()

user_prop_created ( ctx,
cb,
id )

Definition at line 11875 of file z3py.py.

11875def user_prop_created(ctx, cb, id):
11876 prop = _prop_closures.get(ctx)
11877 old_cb = prop.cb
11878 prop.cb = cb
11879 id = _to_expr_ref(to_Ast(id), prop.ctx())
11880 prop.created(id)
11881 prop.cb = old_cb
11882
11883

◆ user_prop_decide()

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

Definition at line 11909 of file z3py.py.

11909def user_prop_decide(ctx, cb, t_ref, idx, phase):
11910 prop = _prop_closures.get(ctx)
11911 old_cb = prop.cb
11912 prop.cb = cb
11913 t = _to_expr_ref(to_Ast(t_ref), prop.ctx())
11914 prop.decide(t, idx, phase)
11915 prop.cb = old_cb
11916

◆ user_prop_diseq()

user_prop_diseq ( ctx,
cb,
x,
y )

Definition at line 11900 of file z3py.py.

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

◆ user_prop_eq()

user_prop_eq ( ctx,
cb,
x,
y )

Definition at line 11891 of file z3py.py.

11891def user_prop_eq(ctx, cb, x, y):
11892 prop = _prop_closures.get(ctx)
11893 old_cb = prop.cb
11894 prop.cb = cb
11895 x = _to_expr_ref(to_Ast(x), prop.ctx())
11896 y = _to_expr_ref(to_Ast(y), prop.ctx())
11897 prop.eq(x, y)
11898 prop.cb = old_cb
11899

◆ user_prop_final()

user_prop_final ( ctx,
cb )

Definition at line 11884 of file z3py.py.

11884def user_prop_final(ctx, cb):
11885 prop = _prop_closures.get(ctx)
11886 old_cb = prop.cb
11887 prop.cb = cb
11888 prop.final()
11889 prop.cb = old_cb
11890

◆ user_prop_fixed()

user_prop_fixed ( ctx,
cb,
id,
value )

Definition at line 11866 of file z3py.py.

11866def user_prop_fixed(ctx, cb, id, value):
11867 prop = _prop_closures.get(ctx)
11868 old_cb = prop.cb
11869 prop.cb = cb
11870 id = _to_expr_ref(to_Ast(id), prop.ctx())
11871 value = _to_expr_ref(to_Ast(value), prop.ctx())
11872 prop.fixed(id, value)
11873 prop.cb = old_cb
11874

◆ user_prop_fresh()

user_prop_fresh ( ctx,
_new_ctx )

Definition at line 11852 of file z3py.py.

11852def user_prop_fresh(ctx, _new_ctx):
11853 _prop_closures.set_threaded()
11854 prop = _prop_closures.get(ctx)
11855 nctx = Context()
11856 Z3_del_context(nctx.ctx)
11857 new_ctx = to_ContextObj(_new_ctx)
11858 nctx.ctx = new_ctx
11859 nctx.eh = Z3_set_error_handler(new_ctx, z3_error_handler)
11860 nctx.owner = False
11861 new_prop = prop.fresh(nctx)
11862 _prop_closures.set(new_prop.id, new_prop)
11863 return new_prop.id
11864
11865
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 11846 of file z3py.py.

11846def user_prop_pop(ctx, cb, num_scopes):
11847 prop = _prop_closures.get(ctx)
11848 prop.cb = cb
11849 prop.pop(num_scopes)
11850
11851

◆ user_prop_push()

user_prop_push ( ctx,
cb )

Definition at line 11840 of file z3py.py.

11840def user_prop_push(ctx, cb):
11841 prop = _prop_closures.get(ctx)
11842 prop.cb = cb
11843 prop.push()
11844
11845

◆ Var()

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

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

Definition at line 1575 of file z3py.py.

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

Referenced by RealVar().

◆ When()

When ( p,
t,
ctx = None )
Return a tactic that applies tactic `t` only if probe `p` evaluates to true.
Otherwise, it returns the input goal unmodified.

>>> t = When(Probe('size') > 2, Tactic('simplify'))
>>> x, y = Ints('x y')
>>> g = Goal()
>>> g.add(x > 0)
>>> g.add(y > 0)
>>> t(g)
[[x > 0, y > 0]]
>>> g.add(x == y + 1)
>>> t(g)
[[Not(x <= 0), Not(y <= 0), x == 1 + y]]

Definition at line 9088 of file z3py.py.

9088def When(p, t, ctx=None):
9089 """Return a tactic that applies tactic `t` only if probe `p` evaluates to true.
9090 Otherwise, it returns the input goal unmodified.
9091
9092 >>> t = When(Probe('size') > 2, Tactic('simplify'))
9093 >>> x, y = Ints('x y')
9094 >>> g = Goal()
9095 >>> g.add(x > 0)
9096 >>> g.add(y > 0)
9097 >>> t(g)
9098 [[x > 0, y > 0]]
9099 >>> g.add(x == y + 1)
9100 >>> t(g)
9101 [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
9102 """
9103 p = _to_probe(p, ctx)
9104 t = _to_tactic(t, ctx)
9105 return Tactic(Z3_tactic_when(t.ctx.ref(), p.probe, t.tactic), t.ctx)
9106
9107
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 8745 of file z3py.py.

8745def With(t, *args, **keys):
8746 """Return a tactic that applies tactic `t` using the given configuration options.
8747
8748 >>> x, y = Ints('x y')
8749 >>> t = With(Tactic('simplify'), som=True)
8750 >>> t((x + 1)*(y + 2) == 0)
8751 [[2*x + y + x*y == -2]]
8752 """
8753 ctx = keys.pop("ctx", None)
8754 t = _to_tactic(t, ctx)
8755 p = args2params(args, keys, t.ctx)
8756 return Tactic(Z3_tactic_using_params(t.ctx.ref(), t.tactic, p.params), t.ctx)
8757
8758
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 8759 of file z3py.py.

8759def WithParams(t, p):
8760 """Return a tactic that applies tactic `t` using the given configuration options.
8761
8762 >>> x, y = Ints('x y')
8763 >>> p = ParamsRef()
8764 >>> p.set("som", True)
8765 >>> t = WithParams(Tactic('simplify'), p)
8766 >>> t((x + 1)*(y + 2) == 0)
8767 [[2*x + y + x*y == -2]]
8768 """
8769 t = _to_tactic(t, None)
8770 return Tactic(Z3_tactic_using_params(t.ctx.ref(), t.tactic, p.params), t.ctx)
8771
8772

◆ Xor()

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

>>> p, q = Bools('p q')
>>> Xor(p, q)
Xor(p, q)
>>> simplify(Xor(p, q))
Not(p == q)

Definition at line 1932 of file z3py.py.

1932def Xor(a, b, ctx=None):
1933 """Create a Z3 Xor expression.
1934
1935 >>> p, q = Bools('p q')
1936 >>> Xor(p, q)
1937 Xor(p, q)
1938 >>> simplify(Xor(p, q))
1939 Not(p == q)
1940 """
1941 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1942 s = BoolSort(ctx)
1943 a = s.cast(a)
1944 b = s.cast(b)
1945 return BoolRef(Z3_mk_xor(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
1946
1947
Z3_ast Z3_API Z3_mk_xor(Z3_context c, Z3_ast t1, Z3_ast t2)
Create an AST node representing t1 xor t2.

Referenced by BoolRef.__xor__().

◆ z3_debug()

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

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

◆ _dflt_fpsort_sbits

int _dflt_fpsort_sbits = 53
protected

Definition at line 9641 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 9639 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 11774 of file z3py.py.

◆ _on_clause_eh

_on_clause_eh = Z3_on_clause_eh(on_clause_eh)
protected

Definition at line 11782 of file z3py.py.

◆ _on_model_eh

_on_model_eh = on_model_eh_type(_global_on_model)
protected

Definition at line 8144 of file z3py.py.

◆ _on_models

dict _on_models = {}
protected

Definition at line 8136 of file z3py.py.

◆ _prop_closures

_prop_closures = None
protected

Definition at line 11831 of file z3py.py.

◆ _ROUNDING_MODES

_ROUNDING_MODES
protected
Initial value:
1= frozenset({
2 Z3_OP_FPA_RM_TOWARD_ZERO,
3 Z3_OP_FPA_RM_TOWARD_NEGATIVE,
4 Z3_OP_FPA_RM_TOWARD_POSITIVE,
5 Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN,
6 Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY
7})

Definition at line 9659 of file z3py.py.

◆ _user_prop_binding

_user_prop_binding = Z3_on_binding_eh(user_prop_binding)
protected

Definition at line 11937 of file z3py.py.

◆ _user_prop_created

_user_prop_created = Z3_created_eh(user_prop_created)
protected

Definition at line 11932 of file z3py.py.

◆ _user_prop_decide

_user_prop_decide = Z3_decide_eh(user_prop_decide)
protected

Definition at line 11936 of file z3py.py.

◆ _user_prop_diseq

_user_prop_diseq = Z3_eq_eh(user_prop_diseq)
protected

Definition at line 11935 of file z3py.py.

◆ _user_prop_eq

_user_prop_eq = Z3_eq_eh(user_prop_eq)
protected

Definition at line 11934 of file z3py.py.

◆ _user_prop_final

_user_prop_final = Z3_final_eh(user_prop_final)
protected

Definition at line 11933 of file z3py.py.

◆ _user_prop_fixed

_user_prop_fixed = Z3_fixed_eh(user_prop_fixed)
protected

Definition at line 11931 of file z3py.py.

◆ _user_prop_fresh

_user_prop_fresh = Z3_fresh_eh(user_prop_fresh)
protected

Definition at line 11930 of file z3py.py.

◆ _user_prop_pop

_user_prop_pop = Z3_pop_eh(user_prop_pop)
protected

Definition at line 11929 of file z3py.py.

◆ _user_prop_push

_user_prop_push = Z3_push_eh(user_prop_push)
protected

Definition at line 11928 of file z3py.py.

◆ sat

Definition at line 7133 of file z3py.py.

◆ unknown

Definition at line 7135 of file z3py.py.

◆ unsat

Definition at line 7134 of file z3py.py.

◆ Z3_DEBUG

Z3_DEBUG = __debug__

Definition at line 67 of file z3py.py.