Putting equality constraint in z3 -


i using z3's python api solve see if set of constraint satisfiable or not. have conditions string , want directly pass them z3 whenever possible, save processing time of transcoding it. if constraint assignment = b best way enter it. want like

    str1 = "a = b"     = bitvec('a', 3)     b = bitvec('b', 3)     s = solver()     s.push()     s.add(str1) 

this program gives error "true, false or z3 boolean expression expected"
please let me know best way it.

you need pass z3 expressions majority of api functions (like solver.add(expr)), not strings. example (z3py link: http://rise4fun.com/z3py/iu0 ):

str1 = "a = b" = bitvec('a', 3) b = bitvec('b', 3) constraint1 = == b # sets constraint1 z3 expression == b s = solver() s.push() # s.add(str1) # error: 'true, false or z3 boolean expression expected' s.add(constraint1) print constraint1 

if want pass strings encoded in infix notation (like "a = b"), should able use python's eval, although may not work full generality, may have write parser, , cannot use eval on rise4fun due sanitizer:

constraint2 = eval(str1) 

here's more details on using eval: z3python: converting string expression

if have strings encoded in smt-lib standard (which uses prefix notation, e.g., "(= b)"), can use parse_smt2_string api function. here's example continuing above:

cstr1 = "(assert (= b))" ds = { 'a' : a, 'b' : b } constraint3 = parse_smt2_string(cstr1, decls=ds) print constraint3 prove(constraint1 == constraint3) 

here's api documentation parse_smt2_string: http://research.microsoft.com/en-us/um/redmond/projects/z3/z3.html#-parse_smt2_string

see related question , answer on using infix output of z3 expressions: how convert z3 expression infix expression?


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -