How to convert z3py expression to smtlib 2 format

My question is related to: Z3: convert Z3py expression to SMT-LIB2?

I am trying to convert a z3py expression from to smtlib2 format. using the following script, but after the conversion, when I submit the result to z3 or any other SMT, I get:

"Syntax error, unexpected let"

Is there a way that I can cast it in smtlib2 format using z3py so that I no longer have to write a long expression.

Below is the code that I use to convert:

def convertor(f, status="unknown", name="benchmark", logic=""):
v = (Ast * 0)()
if isinstance(f, Solver):
a = f.assertions()
if len(a) == 0:
  f = BoolVal(True)
else:
  f = And(*a)
return Z3_benchmark_to_smtlib_string(f.ctx_ref(), name, logic, status, "", 0, v, f.as_ast())

x = Int('x')
y = Int('y')
s = Solver()
s.add(x > 0)
s.add( x < 100000)
s.add(x==2*y)
print convertor(s, logic="QF_LIA")   

and this is the result:

(set-info :status unknown)
(set-logic QF_LIA)
(declare-fun y () Int)
(declare-fun x () Int)
(let (($x34 (= x (* 2 y))))
(let (($x31 (< x 100000)))
(let (($x10 (> x 0)))
(let (($x35 (and $x10 $x31 $x34)))
(assert $x35)))))
(check-sat)
+4
source share
1 answer

.

, Z3. , - ( ) , Z3 :

(set-info :status unknown)
(set-logic QF_LIA)
(declare-fun y () Int)
(declare-fun x () Int)
(assert
(let (($x34 (= x (* 2 y))))
(let (($x31 (< x 100000)))
(let (($x10 (> x 0)))
(and $x10 $x31 $x34)))))
(check-sat)
+1

Source: https://habr.com/ru/post/1533229/


All Articles