mirror of
https://github.com/Z3Prover/z3
synced 2025-04-27 10:55:50 +00:00
add itos/stoi conversion to API. Issue #895
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
e4411265ea
commit
3a0e9e8f53
6 changed files with 108 additions and 24 deletions
|
@ -1011,6 +1011,7 @@ def _coerce_exprs(a, b, ctx=None):
|
|||
b = s.cast(b)
|
||||
return (a, b)
|
||||
|
||||
|
||||
def _reduce(f, l, a):
|
||||
r = a
|
||||
for e in l:
|
||||
|
@ -1296,7 +1297,7 @@ class BoolSortRef(SortRef):
|
|||
if isinstance(val, bool):
|
||||
return BoolVal(val, self.ctx)
|
||||
if __debug__:
|
||||
_z3_assert(is_expr(val), "True, False or Z3 Boolean expression expected")
|
||||
_z3_assert(is_expr(val), "True, False or Z3 Boolean expression expected. Received %s" % val)
|
||||
_z3_assert(self.eq(val.sort()), "Value cannot be converted into a Z3 Boolean value")
|
||||
return val
|
||||
|
||||
|
@ -2012,7 +2013,7 @@ class ArithSortRef(SortRef):
|
|||
if self.is_real():
|
||||
return RealVal(val, self.ctx)
|
||||
if __debug__:
|
||||
_z3_assert(False, "int, long, float, string (numeral), or Z3 Integer/Real expression expected")
|
||||
_z3_assert(False, "int, long, float, string (numeral), or Z3 Integer/Real expression expected. Got %s" % self)
|
||||
|
||||
def is_arith_sort(s):
|
||||
"""Return `True` if s is an arithmetical sort (type).
|
||||
|
@ -9660,6 +9661,29 @@ def Length(s):
|
|||
s = _coerce_seq(s)
|
||||
return ArithRef(Z3_mk_seq_length(s.ctx_ref(), s.as_ast()), s.ctx)
|
||||
|
||||
def 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
|
||||
"""
|
||||
s = _coerce_seq(s)
|
||||
return ArithRef(Z3_mk_str_to_int(s.ctx_ref(), s.as_ast()), s.ctx)
|
||||
|
||||
|
||||
def IntToStr(s):
|
||||
"""Convert integer expression to string"""
|
||||
if not is_expr(s):
|
||||
s = _py2expr(s)
|
||||
return SeqRef(Z3_mk_int_to_str(s.ctx_ref(), s.as_ast()), s.ctx)
|
||||
|
||||
|
||||
def Re(s, ctx=None):
|
||||
"""The regular expression that accepts sequence 's'
|
||||
>>> s1 = Re("ab")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue