Questions tagged [z3py]

Python interface for the Z3 Theorem Prover

z3py - Python interface for the Z3 Theorem Prover. Z3 is a high-performance theorem prover. Z3 supports arithmetic, fixed-size bit-vectors, extensional arrays, datatypes, uninterpreted functions, and quantifiers.

834 questions
2
votes
2 answers

Is it possible to solve for function operations given inputs and outputs?

I have a function that takes 2 integers as input, and outputs an integer. I have a set of inputs and their known outputs. Is it possible to figure out what operations the function is applying to the inputs to arrive at the output? I'm not sure how…
loganrussell48
  • 1,656
  • 3
  • 15
  • 23
2
votes
0 answers

Unable to detect Z3 Solver when it is already imported in Heroku as z3-solver

My friend and I are working on a project that generates a timetable using a Z3 solver in a mobile application. We are using heroku to host the timetable backend and we received this issue while trying to deploy the app, we got an Internal Server…
kmtllesur
  • 21
  • 3
2
votes
2 answers

Algebraic numbers in Z3

The following code sets some Z3 constraints for x,y that are satisfied (only) by: x = sqrt(2) and y = -sqrt(2). x, y = Reals('x y') s = Solver() s.add( x*x == 2 ) s.add( x>0) s.add( y*y == 2 ) s.add( y<0) s.check() m = s.model() val_x =…
makkiato
  • 67
  • 4
2
votes
2 answers

How to bias Z3's (Python) SAT solving towards a criteria, such as 'preferring' to have more negated literals

In Z3 (Python) is there any way to 'bias' the SAT search towards a 'criteria'? A case example: I would like Z3 to obtain a model, but not any model: if possible, give me a model that has a great amount of negated literals. Thus, for instance, if we…
Theo Deep
  • 666
  • 4
  • 15
2
votes
1 answer

Z3 Python: ordering models and accessing their elements

In Z3 (Python), imagine I get a model with the following shape: [c_0 = True, c_3 = False, c_1 = False, c_2 = False] How can I order the variables, so that the assignment is alphabetically ordered? [c_0 = True, c_1 = False, c_2 = False, c_3 =…
Theo Deep
  • 666
  • 4
  • 15
2
votes
1 answer

Add a z3 constraint, such that the value of a z3 variable equals to the return value of some function

I have a Python function that takes a real number and returns a string, e.g. def fun(x): if x == 0.5: return "Hello" else: return "Bye" I start a z3 solver: from z3 import * r = Real('r') s = Solver() Now I want to tell…
jupiter_jazz
  • 333
  • 2
  • 8
2
votes
1 answer

Power and logarithm in Z3

I'm trying to learn Z3 and the following example baffles me: from z3 import * a = Int("a") b = Int("b") print(solve(2**a <= b)) print(solve(a > 0, b > 0, 2**a <= b)) I would expect it returns "[a = 1, b = 2]" but it instead returns "failed to…
Ecir Hana
  • 10,864
  • 13
  • 67
  • 117
2
votes
1 answer

Z3: is Nonlinear integer arithmetic undecidable or semi-decidable

In Z3 (Python), I solved the following: y1,y2,x = Ints('y1 y2 x') univ = ForAll([x], (y1
Theo Deep
  • 666
  • 4
  • 15
2
votes
1 answer

Z3 cannot check equivalence of two formulae

(Why are not the math formulae showing correctly?) I am performing a test over the Z3 library in Python (Collab) to see whether it knows to distinguish formulae. The test is the following: (1) I make a quantifier elimination over a formula $phi_1$,…
Theo Deep
  • 666
  • 4
  • 15
2
votes
0 answers

Newer versions of Z3 no longer keep/print all function instances

Notice in the new versions of Z3, the model only prints the arguments to the function that have a value other than the default. Is there a way to return to the old method of receiving all instances, including those that map to the default…
Dana Chee
  • 21
  • 3
2
votes
1 answer

Better way of reading and parsing DIMACS for Z3

I am very new to SAT and Z3 (Have not even started with SMT yet). I have been playing around with gophersat (A nice Go implementation which works for a good set of SAT problems) and I discovered DIMACS format there. Although I agree that it is not…
SRC
  • 2,123
  • 3
  • 31
  • 44
2
votes
1 answer

Z3 How to check whether a model satisfies a new assertion/constraint

I am using z3py for coding. See the following example. from z3 import * x = Int('x') y = Int('y') s = Solver() s.add(x+y>3) if s.check()==sat: m = s.model() # how to check whether model m satisfies x+y<5 ? print(m)
sirius
  • 567
  • 6
  • 26
2
votes
1 answer

How to represent a symbolic summation in Z3?

I'm trying to represent sum of integers from an integer a to an integer b of the form \sum_{i=a}^b i Of courese there is a closed form solution for this version, but in general I'd like to sum over expressions parameterized by i. I've currently…
enigma
  • 23
  • 3
2
votes
1 answer

Z3PY converting Ints to Python int

Is there a way to convert the Z3PY datatypes to native Python datatypes? When my formula is solved by Z3, I can print it out by calling the model()-function. But how do I save the model output as ordinary ints in variables? So I can use them. Can I…
leiz0r
  • 35
  • 4
2
votes
1 answer

How to force z3py to show multiple answers if that the case?

from z3 import * p = Int('p') q = Int('q') solve(Or(p==1,p==2,p==3), Or(q==1,q==2), Not(p==q), q==1) Gives me [p = 2, q = 1], but p could be 2 or 3. So the answer should be {2,3}. How can I tell z3 to inform me about multiple answers?
trshmanx
  • 600
  • 7
  • 16