Z3

Z3 4.0 Push and Pop In Solver

旧城冷巷雨未停 提交于 2019-12-07 17:18:45
问题 I want to verify my problem using the solver for 2 different constraints. I wrote a sample program for the same, where I have a variable x which I want to check and get a model for x = 0 and x = 1 . I am trying to use Push and Pop in the Solver. However I am not sure about how to do it exactly. I have written the following code. When I try to push the context and pop it back, I get a crash. I do not understand the reason for the crash, but its a Seg Fault. Even if I comment out the push and

Prove 2 formulas equivalent under some conditions?

╄→尐↘猪︶ㄣ 提交于 2019-12-07 12:55:26
问题 Two formulas a1 == a + b and a1 == b are equivalent if a == 0 . I want to find this required condition ( a == 0 ) with Z3 python. I wrote the code below: from z3 import * def equivalence(F, G): s = Solver() s.add(Not(F == G)) r = s.check() if r == unsat: print 'Equ' print s.model() else: print 'Not Equ' a, b = BitVecs('a b', 32) g = True tmp = BitVec('tmp', 32) g = And(g, tmp == a) tmp1 = BitVec('tmp1', 32) g = And(g, tmp1 == b) tmp2 = BitVec('tmp2', 32) g = And(g, tmp2 == (tmp1 + tmp)) a1 =

Z3py returns unknown for equation using pow() function

给你一囗甜甜゛ 提交于 2019-12-07 12:40:34
Z3py returns unknown for the following simple problem using pow() function. import z3; goal = z3.Goal(); goal = z3.Then('purify-arith','nlsat'); solver = goal.solver(); x = z3.Real('x'); solver.add(x <= 1.8); solver.add(x >= 0); z = 10**x; #z = pow(10,x) returns same result solver.add(z >= 0, z <= 1.8); print solver.check() returns unknown Obviously x = 0, z = 1 is a satisfactory solution. Any suggestions in changing the way the equations are constructed, or modifying the tactics are appreciated. Taylor T. Johnson There may be some bug, but the following returns a model of x = 0 and z = 1 ,

How to use Z3Py online to solve problems with Operational Amplifiers

我与影子孤独终老i 提交于 2019-12-07 12:30:50
问题 Find the value of R in the following circuit This problem is solved using the following code: R, V1, V2, Vo = Reals('R V1 V2 Vo') I1 = V1/(R -50) I2 = V2/(R + 10) g = - R*(I1 + I2) print g equations = [Vo == g] print equations problem = [Vo == -2 , V1 == 1, V2 == 0.5, R != -10, R != 50, R > 0] solve(equations + problem) and the corresponding output is: -R·(V1/(R - 50) + V2/(R + 10)) [Vo = -R·(V1/(R - 50) + V2/(R + 10))] [R = 143.8986691902?, V2 = 1/2, V1 = 1, Vo = -2] Other example: Find the

How to get multiple different unsat cores or make the core smaller with z3 (QF_LRA)

浪尽此生 提交于 2019-12-07 10:23:22
问题 After reading the previous questions Getting a "good" unsat core and getting new unsat core, I know that it is impossible to get multiple different unsat cores with z3 at present. Do you have some suggestions to make the unsat core smaller? I am using z3 c++ api to check the satisfiability of a constraints on linear real arithmetic. I found that when adding this line of code p.set(":auto-config",false) as suggested in Getting a "good" unsat core, the size of unsat core becomes smaller.

How to get random results from Microsoft Z3?

一个人想着一个人 提交于 2019-12-07 07:58:41
问题 In Microsoft Z3, when we try to solve a formula, Z3 always returns the results in the same sequence, when there are two or more satisfiable solutions. Is it possible to get random results from Z3 so that for the same input, it will generate different output sequence in different execution. Please note that, I am using C or C# API. I am not using Z3 using smt2lib. So if you can give me a C or C# API function example that can add randomization, it will be more useful. 回答1: (set-option :smt

Solving formulas in parallel with z3

陌路散爱 提交于 2019-12-07 06:09:17
问题 Let's say I have a z3 solver with a certain number of asserted constraints that are satisfiable. Let S be a set of constraints, I would like to verify for every constraint in S whether the formula is still satisfiable when adding the constraint to the solver. This can be easily done sequentially in such a fashion: results = [] for constraint in S: solver.push() solver.add(constraint) results.append(solver.check() == z3.sat) solver.pop() print all(results) Now, I would like to parallelize this

Simplex in z3 via for-all

ぃ、小莉子 提交于 2019-12-06 16:16:44
问题 A very similar questions were asked on SO already, but I couldn't find answer to the following problem. A linear maximization problem can be easily stated using for-all quantifier: obj = f(x) AND \forall x . Ax <= b => f(x) <= obj The queries like above can be posed to z3. Consequently I want to ask whether z3 is smart enough to recognize an LP problem when it sees one and will it apply a simplex method to eliminate a for-all quantifier? I did a few experiments and it seemed to work, but I

retrieve the matched model in Z3py?

匆匆过客 提交于 2019-12-06 15:07:40
问题 In the following working example , How to retrieve the matched model? S, (cl_3,cl_39,cl_11, me_32,m_59,m_81) = EnumSort('S', ['cl_3','cl_39','cl_11','me_32','me_59','me_81']) h1, h2 = Consts('h1 h2', S) def fun(h1 , h2): conds = [ (cl_3, me_32), (cl_39, me_59), (cl_11, me_81), # ... ] and_conds = (And(h1==a, h2==b) for a,b in conds) return Or(*and_conds) For Example: as the following solver s = Solver() x1 = Const('x1', S) x2 = Const('x2', S) s.add(fun(x1,x2)) print s.check() print s.model()

Z3 Time Restricted Optimization

吃可爱长大的小学妹 提交于 2019-12-06 14:55:56
问题 I have seen that Z3 supports optimization via e.g. assert-soft. From what I understood, if given sufficient time, Z3 will report the optimal solution for a given SMT formula. However, I am interested if it is possible to run Z3 for a limited amount of time and have it report the best solution it can find (which does not necessarily mean it is the optimal solution). If I run Z3 on a SMT formula and restrict the time (via parameter -T), it will just report 'timeout' if it did not solve it