1

I'm looking for ideas on how to encode mathematical equations into cnf-sat form, so that they can be solved by an open source SAT solver like MiniSat.

So, how do I convert something like:

3x + 4y - z = 14

-2x - 4z <= -6

x - 3y + z >= 15

into a propositional equation that can be solved by using SAT Solvers.

Any suggestions because I'm stumped??

Kyle Jones
  • 5,492
  • 1
  • 21
  • 30
  • 1
    It's not only you that is stumped. A SAT solver alone cannot solve a linear program. And I am strongly convinced that any encoding is a quite inefficient approximation. Current research provides solvers that *combine* a constraint solver with a linear program solver, but those systems do not try to encode the linear program into SAT. The value domain of `x`, `y` and `z` is ℝ? How do you enumerate ℝ (you don't)? – dhke Dec 08 '15 at 19:40
  • What if the domain of x, y and z is restricted to Z? Also, I'm just trying to show that SAT can be used to solve arithmetic equations, so, would be great if you could help me solve these equations using a combination of a constraint solver (MiniSat), and something else as well? – user3630087 Dec 08 '15 at 23:05
  • 1
    How about starting to search for research papers on the topic? e.g. [Barahona2014](https://www.cs.uic.edu/pub/Isaim2014/WebPreferences/ISAIM2014_Barahona_etal.pdf), which also gives you some references and experiments. It also makes clear a very important fact: The domain of the variables must be *finite*. ℤ is not finite and ℝ is not even countable. – dhke Dec 09 '15 at 07:31

1 Answers1

4

I'm assuming you're looking for an integer solution to your equations since Integer Linear Programming is a known NP-hard problem, as is SAT. (Linear programming without the integer constraint is in P, of course.)

You could convert your equations to a SAT instance but your time would be more fruitfully spent learning how to use an SMT solver, which will let you express your equations much more naturally. As an example, using Microsoft's Z3 solver, your equations above could be solved with this simple program:

(declare-fun x () Int)
(declare-fun y () Int)
(declare-fun z () Int)
(assert (= (+ (* 3 x) (* 4 y) (- z)) 14))
(assert (<= (- (* (- 2) x) (* 4 z)) (- 6)))
(assert (>= (+ (- x (* (- 3) y)) z) 15))
(check-sat)
(get-model)

You can paste that program into an online Z3 sandbox and click the play button to see it solve the equations.

Kyle Jones
  • 5,492
  • 1
  • 21
  • 30