2013-03-27 66 views
0

我想懇請,如何有超過255個參數的Z3 Python函數如何在Z3py函數中使用超過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) 
       ) 
+0

爲什麼不把參數到一些像字典這樣的數據結構? – MattDMo 2013-03-27 16:17:23

回答

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) 
+0

基於此修改,我如何檢索匹配的模型: – 2013-03-27 17:08:03

+0

所有這些代碼與您的代碼具有完全相同的返回值,所以我不知道您的意思? – 2013-03-27 17:23:08

+0

例如,如果我有2個常量x1,x2,並且我想從函數fun中檢索值,則x1 = cl_4712,cl_1871的模型和x2 = me_1935,me_6745的模型。希望它有意義 – 2013-03-27 17:27:41

相關問題