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.
1 Answers
Transcendental numbers and trigonometric functions are usually not supported by SMT solvers.
As Christopher pointed out (thanks!), Z3 does have support for trigonometric functions and transcendentals; but the support is rather quite limited. (In practice, this means you shouldn't expect Z3 to decide every single formula you throw at it; in complicated cases, it's most likely to simply return unknown
.)
See https://link.springer.com/chapter/10.1007%2F978-3-642-38574-2_12 for the related publication. There are some examples in the following discussion thread that can get you started: https://github.com/Z3Prover/z3/issues/680
Also, note that the optimizing solver of Z3 doesn't handle nonlinear equations; so you wouldn't be able to optimize them. For this sort of optimization problems, traditional SMT solvers are just not the right choice.
However, if you're happy with δ-satisfiability (allowing a certain error factor), then check out dReal
, which can deal with trigonometric functions: http://dreal.github.io/ So far as I can tell, however, it doesn't perform optimization.

- 28,120
- 2
- 23
- 40
-
Minor detail: Z3 does support trigonometric functions and transcendentals, but that support is very limited and likely not useful for optimization problems. See also https://link.springer.com/chapter/10.1007%2F978-3-642-38574-2_12 – Christoph Wintersteiger Jul 20 '18 at 10:54
-
Thanks @ChristophWintersteiger, I wasn't aware of this line of work. Edited my answer to reflect the state of the art in Z3. Are the trig functions exposed via the Python API? – alias Jul 20 '18 at 14:37