
Understanding SAT by Implementing a Simple SAT Solver in Python (2014) - c1ccccc1
https://sahandsaba.com/understanding-sat-by-implementing-a-simple-sat-solver-in-python.html
======
wsxcde
The practical significance of SAT is that almost all modern verification
techniques are based on SAT solvers.

The algorithm he describes is not very interesting because it doesn't even
implement unit-propagation. The idea with unit propagation is that if my
current assignment has set a variable A=True and I also have a clause (~A + B)
then B must be true for the instance to be satisfiable. Unit propagation is
about propagating such implied constraints. If he'd implemented unit
propagation along with his brute force search he'd have ended up with what is
called the DPLL algorithm for SAT.

Modern SAT solvers are actually even smarter and have two important
improvements over DPLL: (i) Conflict-Driven Clause Learning (CDCL) which
introduced a very cool technique called non-chronological backtracking, and
(ii) 2-literal watching which is an extremely clever data structure for
efficient unit propagation. Both of these ideas are generalizable to many
other versions of constraint solving (e.g. sudoko, router search, etc.) so
they are well worth learning.

CDCL was introduced by this paper:
[https://dl.acm.org/citation.cfm?id=244560](https://dl.acm.org/citation.cfm?id=244560)
while 2-literal watching is from the Chaff solver:
[https://www.princeton.edu/~chaff/publication/DAC2001v56.pdf](https://www.princeton.edu/~chaff/publication/DAC2001v56.pdf).

~~~
The_rationalist
It is said that SAT is very useful for automatically solving complex problem
where you don't know the solution.

But deep learning neural network are also said to be used when there's no good
solution known.

It's the first time I see the symmetry. When should I use a SAT vs an ANN?

Other than SAT and ANN, are there other kind or technology that automatically
solve/approximate solutions?

~~~
CJefferson
SAT is best when there is one true logical answer. ANN are best when you want
"best advice".

A good guide (in my experience) -- with SAT while the answer is hard to find
it's easy to check (like a Sudoku, or building a timetable with no clashes),
while ANN give answers where verifying the answer isn't easy to perform
computstionally (if I give you a translation of a text into Latin, verifying
it is about as hard as just making a new one from scratch)

~~~
The_rationalist
I am trying to implement a natural language (English) logic checker. It would
detect
[https://en.m.wikipedia.org/wiki/Formal_fallacy](https://en.m.wikipedia.org/wiki/Formal_fallacy)

How could a SAT/SMT help me in this task? I know it's already used for math
theorem checking.

E.g All men are mortal. Socrates is a man. Therefore Socrate is mortal. I have
currently two way to solve syllogisms

One hard-coded Disjonction of cases (but not flexible enough for non canonical
forms of syllogisms)

And a flexible one that generate a graph of transitivity.

Both are 100% accurate.

Could SAT/SMT give me a third way of determining if the conclusion is
logically valid? (not non sequitur)

~~~
CJefferson
This is exactly what SAT and SMT are for.

SMT is some extra stuff on top of SAT. There are a few frameworks which extend
SAT. I'd look at minizinc, it is a fairly easy to use language which can
produce SAT (and SMT, and others) as output. Often encoding things in SAT
directly gets arkward.

~~~
The_rationalist
Thank you but as you say, encoding is limiting. SMT are a progress versus SAT.
But I believe I would need an SMT that take a graph and rules as input and
verify if the graph or parts of the graph satisfy the rules/constraints. And
output me the indexes of the satisfied parts of the graph. I believe such a
thing does not yet exist.

~~~
zzz95
This is what model checkers are for. They internally (might) use SAT solvers
to reason over transition graphs. The general problem for model checkers is of
this form:

System description: Transition system like automata or a guarded command
language which induces a graph.

System Property: Stated in some logic, CTL/LTL

Output: Satisfied, or Unsatisfied with a counter example (usually a path in
the graph which is false).

If your problem can fit into such a framework, have a look at model checkers:
[https://en.wikipedia.org/wiki/List_of_model_checking_tools](https://en.wikipedia.org/wiki/List_of_model_checking_tools)

------
maxmunzel
I wrote a dpll (the standard algorithm for SAT) Implementation in Haskell,
that’s also pretty straight forward:
[https://github.com/maxmunzel/dpll/blob/master/README.md](https://github.com/maxmunzel/dpll/blob/master/README.md)

Feel free to ask any questions.

~~~
hwwc
Thanks! I did a port of it and this could be my way in to discovering more
about SAT solvers. (Doing ports is one of my preferred means of jumpstarting
my motivation for more complex areas of study).

------
grecht
I'm confused why he brings up the four color theorem, since a 4-coloring of a
planar graph can be determined in polynomial time. And he also makes it sound
like the theorem hasn't been proven yet.

~~~
maweki
I think it's fine taking this as a constraint problem. It just means, you know
beforehand that there is a solution. Also, if the underlying problem is in P,
chances are the SAT instance is not that hard.

Also: have you looked at the poly-algorithm for 4-coloring? I rather write the
SAT instance by hand...

------
carapace
If you liked that you might like this. It's a DPLL† SAT Solver based on George
Spencer-Brown's Laws of Form implemented in Python.

[http://joypy.osdn.io/notebooks/Correcet_Programming.html#Dav...](http://joypy.osdn.io/notebooks/Correcet_Programming.html#Davis%E2%80%93Putnam%E2%80%93Logemann%E2%80%93Loveland-\(DPLL\)-algorithm-
SAT-Solver)

One of the interesting things about it is that you don't have to put formulas
into conjunctive normal form.

†
[https://en.wikipedia.org/wiki/Davis%E2%80%93Putnam%E2%80%93L...](https://en.wikipedia.org/wiki/Davis%E2%80%93Putnam%E2%80%93Logemann%E2%80%93Loveland_algorithm)

