|
| 1 | +# Incompatibilities |
| 2 | + |
| 3 | + |
| 4 | +## Definition |
| 5 | + |
| 6 | +Incompatibilities are called "nogoods" in [CDNL-ASP][ass] terminology. |
| 7 | +**An incompatibility is a [conjunction][conjunction] of package terms that must |
| 8 | +be evaluated false**, meaning at least one package term must be evaluated false. |
| 9 | +Otherwise we say that the incompatibility has been "satisfied". |
| 10 | +Satisfied incompatibilities represent conflicts and thus |
| 11 | +the goal of the PubGrub algorithm is to build a solution |
| 12 | +such that none of the produced incompatibilities are ever satisfied. |
| 13 | +If one incompatibility becomes satisfied at some point, |
| 14 | +the algorithm finds the root cause of it and backtracks the partial solution |
| 15 | +before the decision at the origin of that root cause. |
| 16 | + |
| 17 | +> Remark: incompatibilities (nogoods) are the opposite of clauses |
| 18 | +> in traditional conflict-driven clause learning ([CDCL][cdcl]) |
| 19 | +> which are disjunctions of literals that must be evaluated true, |
| 20 | +> so have at least one literal evaluated true. |
| 21 | +> |
| 22 | +> The gist of CDCL is that it builds a solution to satisfy a |
| 23 | +> [conjunctive normal form][cnf] (conjunction of clauses) while |
| 24 | +> CDNL builds a solution to unsatisfy a [disjunctive normal form][dnf] |
| 25 | +> (disjunction of nogoods). |
| 26 | +> |
| 27 | +> In addition, PubGrub is a lazy CDNL algorithm since the disjunction of nogoods |
| 28 | +> (incompatibilities) is built on the fly with the solution. |
| 29 | +
|
| 30 | +[ass]: https://www.sciencedirect.com/science/article/pii/S0004370212000409 |
| 31 | +[cdcl]: https://en.wikipedia.org/wiki/Conflict-driven_clause_learning |
| 32 | +[conjunction]: https://en.wikipedia.org/wiki/Logical_conjunction |
| 33 | +[cnf]: https://en.wikipedia.org/wiki/Conjunctive_normal_form |
| 34 | +[dnf]: https://en.wikipedia.org/wiki/Disjunctive_normal_form |
| 35 | + |
| 36 | +In this guide, we will note incompatibilities with curly braces. |
| 37 | +An incompatibility containing one term \\(T_a\\) for package \\(a\\) |
| 38 | +and one term \\(T_b\\) for package \\(b\\) will be noted |
| 39 | + |
| 40 | +\\[ \\{ a: T_a, b: T_b \\}. \\] |
| 41 | + |
| 42 | +> Remark: in a more "mathematical" setting, we would probably have noted |
| 43 | +> \\( T_a \land T_b \\), but the chosen notation maps well |
| 44 | +> with the representation of incompatibilities as hash maps. |
| 45 | +
|
| 46 | + |
| 47 | +## Properties |
| 48 | + |
| 49 | +**Packages only appear once in an incompatibility**. |
| 50 | +Since an incompatibility is a conjunction, |
| 51 | +multiple terms for the same package are merged with the intersection of those terms. |
| 52 | + |
| 53 | +**Terms that are always satisfied can be removed from an incompatibility**. |
| 54 | +We previously explained that the term \\( \neg [\varnothing] \\) is always evaluated true. |
| 55 | +As a consequence, it can safely be removed from the conjunction of terms that is the incompatibility. |
| 56 | + |
| 57 | +\\[ \\{ a: T_a, b: T_b, c: \neg [\varnothing] \\} = \\{ a: T_a, b: T_b \\} \\] |
| 58 | + |
| 59 | +**Dependencies can be expressed as incompatibilities**. |
| 60 | +Saying that versions in range \\( r_a \\) of package \\( a \\) |
| 61 | +depend on versions in range \\( r_b \\) of package \\( b \\) |
| 62 | +can be expressed by the incompatibility |
| 63 | + |
| 64 | +\\[ \\{ a: [r_a], b: \neg [r_b] \\}. \\] |
| 65 | + |
| 66 | + |
| 67 | +## Unit propagation |
| 68 | + |
| 69 | +If all terms but one of an incompatibility are satisfied by a partial solution, |
| 70 | +we can deduce that the remaining unsatisfied term must be evaluated false. |
| 71 | +We can thus derive a new unit term for the partial solution |
| 72 | +which is the negation of the remaining unsatisfied term of the incompatibility. |
| 73 | +For example, if we have the incompatibility |
| 74 | +\\( \\{ a: T_a, b: T_b, c: T_c \\} \\) |
| 75 | +and if \\( T_a \\) and \\( T_b \\) are satisfied by terms in the partial solution |
| 76 | +then we can derive that the term \\( \overline{T_c} \\) can be added for package \\( c \\) |
| 77 | +in the partial solution. |
| 78 | + |
| 79 | + |
| 80 | +## Rule of resolution |
| 81 | + |
| 82 | +Intuitively, we are able to deduce things such as if package \\( a \\) |
| 83 | +depends and package \\( b \\) which depends on package \\( c \\), |
| 84 | +then \\( a \\) depends on \\( c \\). |
| 85 | +With incompatibilities, we would note |
| 86 | + |
| 87 | +\\[ \\{ a: T_a, b: \overline{T_b} \\}, \quad |
| 88 | + \\{ b: T_b, c: \overline{T_c} \\} \quad |
| 89 | +\Rightarrow \quad \\{ a: T_a, c: \overline{T_c} \\}. \\] |
| 90 | + |
| 91 | +This is the simplified version of the rule of resolution. |
| 92 | +For the generalization, let's reuse the "more mathematical" notation of conjunctions |
| 93 | +for incompatibilities \\( T_a \land T_b \\) and the above rule would be |
| 94 | + |
| 95 | +\\[ T_a \land \overline{T_b}, \quad |
| 96 | + T_b \land \overline{T_c} \quad |
| 97 | +\Rightarrow \quad T_a \land \overline{T_c}. \\] |
| 98 | + |
| 99 | +In fact, the above rule can also be expressed as follows |
| 100 | + |
| 101 | +\\[ T_a \land \overline{T_b}, \quad |
| 102 | + T_b \land \overline{T_c} \quad |
| 103 | +\Rightarrow \quad T_a \land (\overline{T_b} \lor T_b) \land \overline{T_c} \\] |
| 104 | + |
| 105 | +since for any term \\( T \\), the disjunction \\( T \lor \overline{T} \\) is always true. |
| 106 | +In general, for any two incompatibilities \\( T_a^1 \land T_b^1 \land \cdots \land T_z^1 \\) |
| 107 | +and \\( T_a^2 \land T_b^2 \land \cdots \land T_z^2 \\) we can deduce a third, |
| 108 | +called the resolvent whose expression is |
| 109 | + |
| 110 | +\\[ (T_a^1 \lor T_a^2) \land (T_b^1 \land T_b^2) \land \cdots \land (T_z^1 \land T_z^2). \\] |
| 111 | + |
| 112 | +In that expression, only one pair of package terms is regrouped as a union (a disjunction), |
| 113 | +the others are all intersected (conjunction). |
| 114 | +If a term for a package does not exist in one incompatibility, |
| 115 | +it can safely be replaced by the term \\( \neg [\varnothing] \\) in the expression above |
| 116 | +as we have already explained before. |
0 commit comments