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
3
votes
1 answer

How to concatenate regular expressions in z3py?

I want to construct a regular expression such as a* b* c*, There is a function re.++ in z3 that can concatenate 3 regular expressions together so I can construct a* b* c* as below (assert (str.in.re "aabbc" (re.++ (re.* (str.to.re "a")) (re.*…
Huan Sun
  • 147
  • 6
3
votes
2 answers

forall usage in SMT

How does forall statement work in SMT? I could not find information about usage. Can you please simply explain this? There is an example from https://rise4fun.com/Z3/Po5. (declare-fun f (Int) Int) (declare-fun g (Int) Int) (declare-const a…
bc_msa
  • 31
  • 6
3
votes
1 answer

Can you limit a real variable between two bounds?

Can you limit a real variable between two bounds? s = Solver() input = Reals('input') s.add(input >= -2, input <= 2) This example return unsat for me.
3
votes
1 answer

Set Solver for string constraints

I'm trying to implement a solver for a problem (which requires string manipulations) using z3 in python. I've tried reading documentation, but there aren't enough informations. I've also tried to read z3str documentation but I can't find a way to…
meowmeowxw
  • 81
  • 4
3
votes
1 answer

Why is Z3 slow for tiny search space?

I'm trying to make a Z3 program (in Python) that generates boolean circuits that do certain tasks (e.g. adding two n-bit numbers) but the performance is terrible to the point where a brute-force search of the entire solution space would be faster.…
Leo Adberg
  • 342
  • 2
  • 18
3
votes
1 answer

How do I add an offset ot an IndexOf result in z3

How do I add an offset to a value obtained from an IndexOf expression? That is, how do I do this? > import z3 > s = 'hello' > t = 'e' > z3.simplify(z3.IndexOf(s, t, 0) + z3.IntVal(1)) z3.z3types.Z3Exception: Non-sequence passed as a sequence I want…
Rahul Gopinath
  • 808
  • 10
  • 24
3
votes
1 answer

Converting a word into set of bytes in Z3

I'm running the following test in Z3/Python: def test_converting_word_into_byte_array(): bytes_in_word = 4 word_size = 8 * bytes_in_word word = BitVec('word', word_size) word_in_bytes = Array('bytes(word)', BitVecSort(word_size),…
Peteris
  • 3,548
  • 4
  • 28
  • 44
3
votes
0 answers

How to run Z3 using multiple cores?

I am trying to improve the timing of my Z3 code. I have observed that Z3 always utilizes only one core, no matter how many cores my machine has. Is there a way in which Z3 might be able to use all the cores as it will certainly improve performance?
3
votes
1 answer

Creating variables, pairs, and sets in Z3Py

this is a three part question on the use of the Python API to Z3 (Z3Py). I thought I knew the difference between a constant and a variable but apparently not. I was thinking I could declare a sort and instantiate a variable of that sort as…
Motorhead
  • 928
  • 6
  • 16
3
votes
1 answer

Solving linear equations using Z3

I have the following linear equations. m = 2 ** 31 - 1 (207560540 ∗ a + b) modulo m = 956631177 (956631177 ∗ a + b) modulo m = 2037688522 What is the most efficient way to solve these equations? I used Z3 however it did not find any solution. My…
Neon Flash
  • 3,113
  • 12
  • 58
  • 96
3
votes
3 answers

z3 control preference for model return values

Question: Is it possible to control some sort of preference for model return values in z3? Example: Given the following propositional logic formula, there are 2 possible models. a: True, b: True, c: False (preferred) a: True, b: False, c: True…
timmwagener
  • 2,368
  • 2
  • 19
  • 27
3
votes
1 answer

Z3 and strategies: Which strategy to use?

so I'm trying to solve a scheduling problem using z3. I have a set of jobs which needs to be done and a set of resources that are able to do those jobs. The jobs are ordered (total order) and in general the problem is expressed using linear…
Jenni
  • 111
  • 3
3
votes
2 answers

How to print z3 solver results print(s.model()) in order?

Suppose I have a list of 10 variables v = [Real('v_%s' % (i+1)) for i in range(10)] and I want to add a simple constraint like this s = Solver() for i in range(10): s.add(v[i] == i) if s.check() == sat: print(s.model()) So a satisfying…
Francis
  • 189
  • 1
  • 11
3
votes
1 answer

Support of trigonometric functions ( e.g.: cos, tan) in Z3

I would like to use Z3 to optimize a set of equations. The problem hereby is my equations are non-linear but most importantly they do have trigonometric functions. Is there a way to deal with that in z3? I am using the z3py API.
Jenni
  • 111
  • 3
3
votes
1 answer

Z3: how to improve performance?

In following Python code: from itertools import product from z3 import * def get_sp(v0, v1): res = sum([v0[i] * v1[i] for i in range(len(v0))]) return res def get_is_mod_partition(numbers): n = len(numbers) mod_power = 2**n for…
DSblizzard
  • 4,007
  • 7
  • 48
  • 76