mirror of
https://github.com/Z3Prover/z3
synced 2025-04-24 17:45:32 +00:00
allow coercion from Boolean to Integers and reals
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
6c1a5390ef
commit
99861ffc32
1 changed files with 13 additions and 0 deletions
|
@ -1228,6 +1228,15 @@ class BoolSortRef(SortRef):
|
|||
_z3_assert(self.eq(val.sort()), "Value cannot be converted into a Z3 Boolean value")
|
||||
return val
|
||||
|
||||
def subsort(self, other):
|
||||
return isinstance(other, ArithSortRef)
|
||||
|
||||
def is_int(self):
|
||||
return True
|
||||
|
||||
def is_bool(self):
|
||||
return True
|
||||
|
||||
class BoolRef(ExprRef):
|
||||
"""All Boolean expressions are instances of this class."""
|
||||
def sort(self):
|
||||
|
@ -1900,6 +1909,10 @@ class ArithSortRef(SortRef):
|
|||
return val
|
||||
if val_s.is_int() and self.is_real():
|
||||
return ToReal(val)
|
||||
if val_s.is_bool() and self.is_int():
|
||||
return If(val, 1, 0)
|
||||
if val_s.is_bool() and self.is_real():
|
||||
return ToReal(If(val, 1, 0))
|
||||
if __debug__:
|
||||
_z3_assert(False, "Z3 Integer/Real expression expected" )
|
||||
else:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue