【问题标题】:How can i have more than 255 arguments in Z3py function?如何在 Z3py 函数中有超过 255 个参数?
【发布时间】:2013-03-17 19:43:15
【问题描述】:

我想问一下,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)
                )

【问题讨论】:

  • 为什么不将参数放入某种数据结构中,比如字典?

标签: python z3 smt constraint-programming


【解决方案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)

【讨论】:

  • 基于此修改,我如何检索匹配的模型:
  • 所有这段代码的返回值和你的代码完全一样,所以我不知道你的意思是什么?
  • 例如,如果我有 2 个常量 x1,x2 ,并且我想从函数 fun 、 x1=cl_4712、cl_1871 的模型和 x2 = me_1935,me_6745 的模型中检索值。 . 希望它有意义
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-06-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多