@@ -139,53 +139,3 @@ Here are some of these:
139139 Only adding dependencies should impact that.
140140- ** Removing a package that does not appear in a solution cannot break that solution** .
141141 Just as before, it should not impact the existence of a solution.
142-
143-
144- ## Comparison with a SAT solver
145-
146- The [ SAT problem] ( https://en.wikipedia.org/wiki/Boolean_satisfiability_problem )
147- aims at answering if there exist a set of Boolean variables assignments
148- satisfying a given Boolean expression.
149- So if we can formulate dependencies as a Boolean expression,
150- we can use these well tested tools to compare
151- the result of pubgrub with the one of a SAT solver.
152- SAT solvers usually work with Boolean expressions in a
153- [ conjunctive normal form (CNF)] ( https://en.wikipedia.org/wiki/Conjunctive_normal_form )
154- meaning a conjunction of clauses, an "_ AND_ of _ ORs_ ".
155- So our goal is to convert the following rules of dependency solving into a set of clauses.
156-
157- 1 . There must be only one version per package.
158- 2 . Dependencies of a package must be present if that package is present.
159- 3 . The root package must be present in the solution.
160-
161- Each package version \\ ((p,v)\\ ) is associated to a unique Boolean variable
162- \\ (b_ {p,v}\\ ) that can be ` true ` or ` false ` .
163- For a given package \\ (p\\ ) and its set of existing versions \\ (V_p\\ ),
164- the property (1) can be expressed by the set of clauses
165-
166- \\ [ \\ { \neg b_ {p,v_1} \lor \neg b_ {p,v_2} \ | \ (v_1, v_2) \in V_p^2, v_1 \neq v_2 \\ }. \\ ]
167-
168- Each one of these clauses specifies that \\ (v_1\\ ) or \\ (v_2\\ ) is not present
169- in the solution for package \\ (p\\ ).
170- These clauses are generated by the ` sat_at_most_one ` function in the testing code.
171- A more efficent approach is used when a package has 4 or more versions
172- but the idea is the same.
173- For a given package version \\ ((p,v)\\ ) depending on another package \\ (d\\ )
174- at versions \\ ((v_1, v_2, \cdots, v_k)\\ ), the property (2) can be encoded by the clause
175-
176- \\ [ \neg b_ {p,v} \lor b_ {d,v_1} \lor b_ {d,v_2} \lor \cdots \lor b_ {d,v_k} \\ ]
177-
178- specifying that either \\ ((p,v)\\ ) is not present in the solution,
179- or at least one of versions \\ ((v_1, v_2, \cdots, v_k)\\ ) of package \\ (d\\ )
180- is present in the solution.
181- Finally, the last constraint of version solving (3) is encoded with the following unit clause,
182-
183- \\ [ b_ {r,v_r} \\ ]
184-
185- where \\ ((r, v_r)\\ ) is the root package version for which we are solving dependencies.
186-
187- Once the conversion to the SAT formulation is done,
188- we can verify the following property:
189-
190- - ** If pubgrub finds a solution, the SAT solver is also satisfied by that solution.**
191- - ** If pubgrub does not find a solution, neither does the SAT solver.**
0 commit comments