mirror of
https://github.com/Z3Prover/z3
synced 2025-04-27 10:55:50 +00:00
add at-least and pbge to API, fix for issue #864
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
c69a86e647
commit
8d09b6e4a8
11 changed files with 182 additions and 48 deletions
|
@ -7617,11 +7617,6 @@ def AtLeast(*args):
|
|||
>>> a, b, c = Bools('a b c')
|
||||
>>> f = AtLeast(a, b, c, 2)
|
||||
"""
|
||||
def mk_not(a):
|
||||
if is_not(a):
|
||||
return a.arg(0)
|
||||
else:
|
||||
return Not(a)
|
||||
args = _get_args(args)
|
||||
if __debug__:
|
||||
_z3_assert(len(args) > 1, "Non empty list of arguments expected")
|
||||
|
@ -7629,10 +7624,25 @@ def AtLeast(*args):
|
|||
if __debug__:
|
||||
_z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
|
||||
args1 = _coerce_expr_list(args[:-1], ctx)
|
||||
args1 = [ mk_not(a) for a in args1 ]
|
||||
k = len(args1) - args[-1]
|
||||
k = args[-1]
|
||||
_args, sz = _to_ast_array(args1)
|
||||
return BoolRef(Z3_mk_atmost(ctx.ref(), sz, _args, k), ctx)
|
||||
return BoolRef(Z3_mk_atleast(ctx.ref(), sz, _args, k), ctx)
|
||||
|
||||
|
||||
def _pb_args_coeffs(args):
|
||||
args = _get_args(args)
|
||||
args, coeffs = zip(*args)
|
||||
if __debug__:
|
||||
_z3_assert(len(args) > 0, "Non empty list of arguments expected")
|
||||
ctx = _ctx_from_ast_arg_list(args)
|
||||
if __debug__:
|
||||
_z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
|
||||
args = _coerce_expr_list(args, ctx)
|
||||
_args, sz = _to_ast_array(args)
|
||||
_coeffs = (ctypes.c_int * len(coeffs))()
|
||||
for i in range(len(coeffs)):
|
||||
_coeffs[i] = coeffs[i]
|
||||
return ctx, sz, _args, _coeffs
|
||||
|
||||
def PbLe(args, k):
|
||||
"""Create a Pseudo-Boolean inequality k constraint.
|
||||
|
@ -7640,38 +7650,25 @@ def PbLe(args, k):
|
|||
>>> a, b, c = Bools('a b c')
|
||||
>>> f = PbLe(((a,1),(b,3),(c,2)), 3)
|
||||
"""
|
||||
args = _get_args(args)
|
||||
args, coeffs = zip(*args)
|
||||
if __debug__:
|
||||
_z3_assert(len(args) > 0, "Non empty list of arguments expected")
|
||||
ctx = _ctx_from_ast_arg_list(args)
|
||||
if __debug__:
|
||||
_z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
|
||||
args = _coerce_expr_list(args, ctx)
|
||||
_args, sz = _to_ast_array(args)
|
||||
_coeffs = (ctypes.c_int * len(coeffs))()
|
||||
for i in range(len(coeffs)):
|
||||
_coeffs[i] = coeffs[i]
|
||||
ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
|
||||
return BoolRef(Z3_mk_pble(ctx.ref(), sz, _args, _coeffs, k), ctx)
|
||||
|
||||
def 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)
|
||||
"""
|
||||
ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
|
||||
return BoolRef(Z3_mk_pbge(ctx.ref(), sz, _args, _coeffs, k), ctx)
|
||||
|
||||
def PbEq(args, k):
|
||||
"""Create a Pseudo-Boolean inequality k constraint.
|
||||
|
||||
>>> a, b, c = Bools('a b c')
|
||||
>>> f = PbEq(((a,1),(b,3),(c,2)), 3)
|
||||
"""
|
||||
args = _get_args(args)
|
||||
args, coeffs = zip(*args)
|
||||
if __debug__:
|
||||
_z3_assert(len(args) > 0, "Non empty list of arguments expected")
|
||||
ctx = _ctx_from_ast_arg_list(args)
|
||||
if __debug__:
|
||||
_z3_assert(ctx is not None, "At least one of the arguments must be a Z3 expression")
|
||||
args = _coerce_expr_list(args, ctx)
|
||||
_args, sz = _to_ast_array(args)
|
||||
_coeffs = (ctypes.c_int * len(coeffs))()
|
||||
for i in range(len(coeffs)):
|
||||
_coeffs[i] = coeffs[i]
|
||||
ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
|
||||
return BoolRef(Z3_mk_pbeq(ctx.ref(), sz, _args, _coeffs, k), ctx)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue