Can a SAT solver be used to find all solutions? - satisfiability

I wrote an answer to what I thought was a quite interesting question, but unfortunately the question was deleted by its author before I could post. I'm reposting a summary of the question and my answer here in case it might be of use to anyone else.
Suppose I have a SAT solver that, given a Boolean formula in conjunctive normal form, returns either a solution (a variable assignment that satisfies the formula) or the information that the problem is unsatisfiable.
Can I use this solver to find all the solutions?

There is definitely a way to use the SAT solver you described to find all the solutions of a SAT problem, although it may not be the most efficient way.
Just use the solver to find a solution to your original problem, add a clause that does nothing except rule out the solution you just found, use the solver to find a solution to the new problem, and so forth. Keep going until you get a problem that's unsatisfiable.
For example, suppose you want to satisfy (X or Y) and (X or Z). There are five solutions:
Four with X true, Y and Z arbitrary.
One with X false, Y and Z true.
So you run your solver, and let's say it gives you the solution (X, Y, Z) = (T, F, F). You can rule out this solution---and only this solution---with the constraint
not (X and (not Y) and (not Z))
This constraint can be rewritten as the clause
(not X) or Y or Z
So now you can run your solver on the new problem
(X or Y) and (X or Z) and ((not X) or Y or Z)
and so forth.
Like I said, this is a way to do what you want, but it probably isn't the most efficient way. When your SAT solver is looking for a solution, it learns a lot about the problem, but it doesn't return all that information to you---it just gives you the solution it found. When you run the solver again, it has to re-learn all the information that was thrown away.

Sure it can. When MiniSat[1] finds a solution
s SATISFIABLE
v 1 2 -3 0
(solution 1=True, 2=True, 3=False) then you have to put into the original CNF[2] a clause that bans this solution:
-1 -2 3 0
(which means, either 1 or 2 must be False or 3 must be True). Then you solve again. You do this until the solver returns UNSAT i.e. that there are no more solutions to the problem. You will insert one clause for each iteration, and each clause will have the same format as the solution except that it's all inverted and has a 0 at the end
It's much faster to do this using the C++ interface of MiniSat, as it can then save intermediate data and the iterations will be faster.
[1] http://minisat.se/
[2] http://fairmut3x.wordpress.com/2011/07/29/cnf-conjunctive-normal-form-dimacs-format-explained/

Related

Why does with scala.math.BigInt(-1).mod(-2) return -3?

I was looking into the difference between x % y and x mod y, which I believe I understood for positive values of y.
During experimentation, it came up that scala.math.BigInt(-1) mod -2 evaluates as -3, which makes absolutely no sense to me. I did not find a formal description of scala's BigInt behavior, but Java's says it should throw an exception if the second argument is negative.
What's going on with this?

OCaml "reading" a matrix (list of lists)

I have this problem in which i want to change the value of the element in col ln of a matrix i already have a function for that but i think i can make a better one, the only thing is i can´t think of another way of getting an element from the matrix and putting it back
i can get it using
List.nth c (List.nth lb m)
but im having trouble putting it back
what i have for now is (fun left and right not done)
matrixleft m #(( List.nth c (List.nth lb m) ) + 1 )::matrixright m
This code looks OK to me on a complexity basis, though it's going to traverse the input matrix twice--once to get the old value and once to install the new one. You can get the answer by traversing just once if you don't mind some more fiddly coding.
If you aren't following some externally imposed requirement, you would be better off using a real matrix (an array of arrays). Then there's no traversing, so you get constant time updates.

Predicates and quantifiers. (Discrete mathematics)

I would like to be sure that my answer is true.
the question is :
Let I (x) be the statement “x has an Internet connection”
and C(x, y) be the statement “x and y have chatted over
the Internet,” where the domain for the variables x and y
consists of all students in your class. Use quantifiers to
express each of these statements:
** Exactly one student in your class has an Internet connection.
my answer is: ∃x∀y(x=y ↔ I(y)).
Yes, it works.
An alternative approach would be to try to do it in two steps, and take a conjunction.
First would be "someone has internet" exists X. I(x) and second would be "if two people have internet then they are the same person" forall x,y. I(x) and I(y) -> x = y.
This way is 'simpler' in that there is less quantifier depth. Yours has a quantifier depth of two, and mine has only one.
But yours is more elegant, so YMMV.

Boolean Expression Evaluation For ExNor Gate

I know that an xnor expression can be broken up as follows:
X xnor Y = X'Y' + XY
But but I know that sume of the complement of the same combination (x+x') is 1 always therefore shouldn't xnor be always equal to 1?
I got confused in this question when I was trying to solve the following problem:
Z=X*Y where * denotes xnor. Evaluate Z*X.
My answer was 1, which according to the provided solution is incorrect the correct solution was given Y.
How? Thanks for the help.

Can matlab (or mupad) evaluate symbolic expressions containing non-commuting operators?

Say I give something like AB+AB+BA to matlab (or mupad), and ask it to simplify it. the answer should be: 2AB+BA. Can this be done in matlab or mupad?
Edit:
Ok, this is feeling rediculous. I'm trying to do this in either matlab or mulab, and.. it's frustrating not knowing how to do what should be the simplest things, and not being able to find the answers right away via google.
I want to expand the following, multiplied together, as a taylor series:
eq1 := exp(g*l*B):
eq2 := exp(l*A):
eq3 := exp((1-g)*l*B):
g is gamma, l is lambda (don't know how to represent either of these in matlab or mulab). A and B don't commute. I want to multiply the three exponentials together, expand, select all terms of a given power in lambda, and simplify the result. Is there a simple way to do this? or should I give up and go to another system, like maple?
This is mupad, not matlab:
operator("x", _vector_product, Binary, 1999):
A x B + A x B + B x A
returns
2 A x B + B x A
The vetor product is used, simply because it matches the described requirements.