如何在Z3py函数中拥有超过255个参数?

时间:2013-03-27 16:12:57

标签: python z3 smt constraint-programming

我想问一下,如何在Z3 Python函数中拥有超过255个参数

    h1, h2 = Consts('h1 h2', S)
     def fun(h1 , h2):
          return Or(
 And( h1 == cl_4712, h2 == me_1935),
 And( h1 == cl_1871, h2 == me_1935),
 And( h1 == cl_4712, h2 == me_1935),
                   .
                   .
                   .
  And( h1 == cl_1871, h2 == me_6745)
                )

1 个答案:

答案 0 :(得分:1)

func(arg1, arg2, arg3)

完全等同于

args = (arg1, arg2, arg3)
func(*args)

因此,将参数作为单个可迭代提供:

Or(*(And(...),...))

或者更清楚:

conditions = (And(...), ...)
Or(*conditions)

或许你可以只提供一个产生你条件的发电机:

def AndCond(a, b):
    for ....:
        yield And(...)

Or(*AndCond(v1, v2))

我可能会写这样的代码:

h1, h2 = Consts('h1 h2', S)
def fun(h1 , h2):
    # possibly this should be a set() or frozenset()
    # since logically every pair should be unique?
    h1_h2_and_conds = [
        (cl_4712, me_1935),
        (cl_1871, me_1935),
        (cl_1871, me_6745),
        # ...
    ]
    and_conds = (And(h1==a, h2==b) for a,b in h1_h2_and_conds)
    return Or(*and_conds)